我正在使用South来生成和应用迁移,而不是自己管理。不幸的是,南方拒绝实际做任何事情。成绩单如下:
[graffias:~/testing.tustincommercial.com/oneclickcos]$ python ./manage.py schemamigration mainapp --auto
You cannot use --auto on an app with no migrations. Try --initial.
[graffias:~/testing.tustincommercial.com/oneclickcos]$ python ./manage.py schemamigration mainapp --initial
+ Added model mainapp.CompanyUK
+ Added model mainapp.CompanyName
+ Added model mainapp.Individual
+ Added model mainapp.Director
+ Added model mainapp.DirectorsIndividual
+ Added model mainapp.DirectorsCorporate
+ Added model mainapp.ShareCapitalClass
+ Added model mainapp.Member
+ Added model mainapp.MembersIndividual
+ Added model mainapp.MemberGeneric
+ Added model mainapp.CompanyManager
+ Added model mainapp.PendingRegistration
+ Added model mainapp.PendingAuthorisation
Created 0001_initial.py. You can now apply this migration with: ./manage.py migrate mainapp
[graffias:~/testing.tustincommercial.com/oneclickcos]$ python ./manage.py migrate mainapp
Running migrations for mainapp:
- Nothing to migrate.
- Loading initial data for mainapp.
No fixtures found.
[graffias:~/testing.tustincommercial.com/oneclickcos]$
如您所见,South认为没有任何事可做。但是,最后三个模型是全新的,并且数据库中没有表。
除了关闭数据库以使South重新工作之外,我还能做些什么?
我无意为项目的其余部分手动编写迁移,但是如果有帮助,我会编写一个迁移。
最佳答案
我想您可能因为不使用./manage.py convert_to_south mainapp
开始而陷入困境。也许您可以通过执行以下操作来更正此问题:
(1)让South相信您没有执行第一次迁移,因此请归零./manage.py migrate --fake mainapp zero
(2)真正迁移到第一次迁移。./manage.py migrate mainapp
但是对于我可以回答的问题,您已经在数据库中建立了一些不带South的模型,否则就不必使用--initial
了。如果是这样,它可能会提示已经存在的列。
您可以通过以下方式更改这种情况:
(1)通过删除mainapp/migrations/0001_initial.py清除第一个schemamigration。您不需要直接摆弄South数据库表,--delete-ghost-migrations
会解决这个问题。
(2)./manage.py syncdb
South希望数据库与模型同步。
(3)./manage.py convert_to_south mainapp
实际上让South处理数据库和迁移。
(4)./manage.py migrate --delete-ghost-migrations mainapp
移至第一个迁移并从数据库中删除您从migrations/中删除的旧的第一个迁移
关于python - South不会为现有应用程序生成或应用迁移,而要迁移的更改,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7300316/