为什么我的南迁不成功?

2024-04-28 10:32:03 发布

您现在位置:Python中文网/ 问答频道 /正文

首先,我创建我的数据库。

create database mydb;

我在安装的应用程序中添加了“south”。然后,我转到本教程:http://south.aeracode.org/docs/tutorial/part1.html

教程告诉我要这样做:

$ py manage.py  schemamigration wall --initial
>>> Created 0001_initial.py. You can now apply this migration with: ./manage.py migrate wall

太好了,现在我要移民了。

$ py manage.py migrate wall

但它给了我这个错误。。。

django.db.utils.DatabaseError: (1146, "Table 'fable.south_migrationhistory' doesn't exist")

所以我使用Google(它永远都不起作用。因此我在Stackoverflow上问了870个问题,我得到了这个页面:http://groups.google.com/group/south-users/browse_thread/thread/d4c83f821dd2ca1c

好吧,所以我按照指示去做

>> Drop database mydb;
>> Create database mydb;
$ rm -rf ./wall/migrations
$ py manage.py syncdb

但是当我运行syncdb时,Django会创建一堆表。是的,它创建了south_migrationhistory表,但也创建了我的应用程序表。

Synced:
 > django.contrib.admin
 > django.contrib.auth
 > django.contrib.contenttypes
 > django.contrib.sessions
 > django.contrib.sites
 > django.contrib.messages
 > south
 > fable.notification
 > pagination
 > timezones
 > fable.wall
 > mediasync
 > staticfiles
 > debug_toolbar

Not synced (use migrations):
 - 
(use ./manage.py migrate to migrate these)

酷…现在它告诉我要迁移这些。所以,我这样做:

$ py manage.py  migrate wall
The app 'wall' does not appear to use migrations.

好吧,很好。我将在最初的迁移中添加wall。

$ py manage.py schemamigration wall --initial

然后我迁移:

$ py manage.py migrate wall

你知道吗?它给了我一个B:

_mysql_exceptions.OperationalError: (1050, "Table 'wall_content' already exists")

对不起,这真让我生气。有人能帮忙吗?谢谢。

我怎样才能让南方的工作和同步正确的一切?我唯一能想到的是从已安装的应用程序中删除我的应用程序,然后运行syncdb,然后重新添加它。

那太傻了。


Tags: djangopy应用程序manageusemigrationsmigratecontrib
2条回答

这就是我让事情运转的方式。

pip install South

# add 'south', to INSTALL_APPS, then
python manage.py syncdb

# For existing project + database
python manage.py convert_to_south app_name

# Thereafter, call them per model changes
python manage.py schemamigration app_name --auto
python manage.py migrate app_name

参考文献:

http://garmoncheg.blogspot.com/2011/08/django-how-and-why-to-use-migrations.htmlhttp://www.djangopro.com/2011/01/django-database-migration-tool-south-explained/

您正在使用的教程状态:

(If this fails complaining that south_migrationhistory does not exist, you forgot to run syncdb after you installed South.)

假设你的帖子准确地详细描述了你已经采取的步骤,那么按照这个链接似乎会显示你在设置新应用之前错过了一个步骤。由于您正在学习在新应用程序上设置迁移的教程,因此顺序如下:

  1. south添加到INSTALLED_APPS
  2. 运行syncdb
  3. 然后按照教程进行操作。

也就是说,在添加新应用程序的模型之前,您应该已经运行了syncdb。从INSTALLED_APPS中删除应用程序的解决方案应该是可行的,但值得注意的是,这实际上只是一个“愚蠢”的解决方案,因为您之前错过了一步。如果在创建应用程序的模型之前运行了syncdb,则不必使用解决方案。

相关问题 更多 >