我正在从配置文件模型设置更改为扩展用户模型。我试图根据this guide设置我的南迁移。我还有一些其他模型引用了User模型,因此当我自动生成模式迁移时,我会得到以下几行:
db.alter_column(u'app_model', 'user',
self.gf('django.db.models.fields.related.ForeignKey')(to=orm['app.user']))
问题是当我尝试迁移时,这些迁移会导致South中断:
FATAL ERROR - The following SQL query failed: INSERT INTO "_south_new_app_model" () SELECT FROM "app_model";
The error was: near ")": syntax error
! Error found during real run of migration! Aborting.
! 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.
! You *might* be able to recover with:
! The South developers regret this has happened, and would
! like to gently persuade you to consider a slightly
! easier-to-deal-with DBMS (one that supports DDL transactions)
! NOTE: The error which caused the migration to fail is further up.
Error in migration: app:0018_auto__chg_field_model_user.py
DatabaseError: near ")": syntax error
注意:这是使用./manage.py schemamigration app --auto
创建的迁移。我没有编辑它。
alter_table
行,一切似乎都会继续有效。这是一个可怕的,可怕的想法,还是没关系?
答案 0 :(得分:1)
Sqlite3是个问题。正如您可能看到here,sqlite3仅支持alter table
操作的有限子集,因此导致South
无法迁移。如果您需要这样做,您必须将测试数据库移植到另一个支持alter table
的引擎。我建议,有时迁移可能很棘手,你可能认为它有效,但总是更好地测试它。
如果您认为工作正常,那么继续并忽略错误,但请注意,它现在可能正在运行但是迁移可能没有成功,之后您会在开发环境中发现奇怪的数据库相关错误。