Django 1.7 makemigrations将表重命名为None [英] Django 1.7 makemigrations renaming tables to None
问题描述
我不得不将一些模型从一个应用程序迁移到另一个应用程序,并且我遵循了此答案 https:// stackoverflow上的说明。 com / a / 26472482/188614 。
基本上,我使用了 python manage.py生成的
,将它们包装在 CreateModel
迁移makemigrations state_operations
中,并在'db_table'
元选项中添加
一切正常, new_app
上的模型正确使用了旧表。
但是如果我运行 python manage.py makemigrations new_app
,它会为每个表创建 AlterModelTable
迁移,并将其重命名为无
,像这样:
I had to move a few models from one app to another, and I followed the instructions on this answer https://stackoverflow.com/a/26472482/188614.
Basically I used the CreateModel
migrations generated by python manage.py makemigrations
, wrapped them inside state_operations
, and added the 'db_table'
meta option with the old table's name.
Everything works fine, the models on the new_app
are corretly using the old tables.
But if I run python manage.py makemigrations new_app
it creates an AlterModelTable
migration for each table renaming them as None
, like this:
migrations.AlterModelTable(
name='cidade',
table=None,
),
这是错误还是预期的行为?
Is this a bug, or expected behaviour?
推荐答案
我只是遇到了这个问题我自己。
I just had this problem myself.
您遵循的答案包括在 new_app
的迁移中:
The answer you were following includes this in the migration in new_app
:
options={
'db_table': 'newapp_themodel',
},
此选项字典应反映模型中 Meta
类设置的值。就我而言,我没有在Meta中设置 db_table
,而是盲目复制了选项代码。
This options dict should reflect the values set by the Meta
class on your model. In my case, I was not setting db_table
in Meta, but had blindly copied the options code.
您需要更新 newapp
迁移中的选项,以删除 db_table
值(如果未在 Meta
或与您在 Meta
中设置的值匹配。
You need to update the options in your migration for newapp
to either remove the db_table
value if you don't set it in Meta
or to match the value you set in Meta
.
这篇关于Django 1.7 makemigrations将表重命名为None的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!