Django2.0向已存在的模型里新增字段,报错的问题??

Django2.0向已存在的模型里新增字段

然后执行 Python manage.py makemigrations appname 正常
但是执行 Python manage.py migrate 提示表已存在

请问怎么向已存在的模型里新增字段

阅读 3.2k
2 个回答

第二步添加参数,运行下面命令:

 python manage.py migrate --fake-initial

文档的具体内容如下

Adding migrations to new apps is straightforward - they come preconfigured to accept migrations, and so just run makemigrations once you’ve made some changes.

If your app already has models and database tables, and doesn’t have migrations yet (for example, you created it against a previous Django version), you’ll need to convert it to use migrations; this is a simple process:

$ python manage.py makemigrations your_app_label
This will make a new initial migration for your app. Now, run python manage.py migrate --fake-initial, and Django will detect that you have an initial migration and that the tables it wants to create already exist, and will mark the migration as already applied. (Without the migrate --fake-initial flag, the command would error out because the tables it wants to create already exist.)

你有把迁移文件删掉吧。。。请妥善保管好迁移文件。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题