Django 1.7 makemigrations renaming tables to None

烈酒焚心 提交于 2019-12-08 21:06:29

问题


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?


回答1:


I just had this problem myself.

The answer you were following includes this in the migration in new_app:

options={
    'db_table': 'newapp_themodel',
},

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.

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.



来源:https://stackoverflow.com/questions/28053937/django-1-7-makemigrations-renaming-tables-to-none

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!