Django South向管理员添加了模型但是给出了DatabaseError

时间:2012-11-30 10:35:19

标签: django model admin add django-south

我刚刚开始使用带有现有应用程序的南方,并且在向数据库添加新模型后,我可以在管理员中查看模型,但是当点击它们以查看模型详细信息时错误

我尝试做南方的syncdb:

python manage.py schemamigration directory --initial

python manage.py migrate directory

其中directory是应用程序名称。

因此,当我尝试在管理员中查看模型时,我得到以下内容:

Exception Type: DatabaseError

Exception Value: (1146, "Table 'omada.directory_drift' doesn't exist")

其中Drift是我添加到models.py的模型,然后在admin.py中注册 - omada是网站名称。

更多信息:

来自django网站的回溯以:

结尾
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py" in execute


  114.             return self.cursor.execute(query, args) File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.4b5-py2.7-linux-i686.egg/MySQLdb/cursors.py" in execute
  201.             self.errorhandler(self, exc, value) File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.4b5-py2.7-linux-i686.egg/MySQLdb/connections.py" in defaulterrorhandler
  36.     raise errorclass, errorvalue

执行时

python manage.py migrate directory

我收到的错误始于:

FATAL ERROR - The following SQL query failed: CREATE TABLE `directory_building`
 ! Since you have a database that does not support running
 ! schema-altering statements in transactions, we have had
 ! to leave it in an interim state between migrations.

听起来不太有希望:S,并以:

结束
  File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.4b5-py2.7-linux-i686.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler                
    raise errorclass, errorvalue
django.db.utils.DatabaseError: (1050, "Table 'directory_building' already exists")

提前感谢所有花时间阅读并提供帮助的人!

1 个答案:

答案 0 :(得分:1)

您可能会发现此guide有用。

由于你只是从南方开始,我建议从头开始:

  1. 从数据库中删除南表(south_migrationhistory)

  2. 从app.migrations文件夹中删除迁移

  3. 按照指南
  4. 让南方处于糟糕状态非常容易,所以你只需要获得一些经验。但是,随着项目规模的扩大,你无法生存。