Django 1.7的makemigrations命令没有任何作用

6

我在我的Heroku服务器上不断运行python manage.py makemigrations,但无论我运行多少次,都会得到以下信息:

$heroku run python manage.py makemigrations
Running `python manage.py makemigrations` attached to terminal... up, run.2680
Migrations for 'default':
  0002_auto_20141120_2007.py:
    - Alter field user on usersocialauth

如果我运行heroku run python manage.py migrate

它会返回以下内容:

Running `python manage.py migrate` attached to terminal... up, run.1285
Operations to perform:
  Synchronize unmigrated apps: baflist_core, rest_framework, localflavor, storages
  Apply all migrations: admin, userAccount, contenttypes, sessions, default, location, messaging, forum, auth, posts
Synchronizing apps without migrations:
  Creating tables...
  Installing custom SQL...
  Installing indexes...
Running migrations:
  No migrations to apply.
  Your models have changes that are not yet reflected in a migration, and so won't be applied.
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

不可否认,我只知道足够的关于postgres和迁移的知识,以至于会有危险因素,所以我想在这里问问。有人遇到过这种情况吗?


你不应该在服务器上运行 makemigrations。在本地运行它,将创建的迁移文件添加到 git 中,然后推送,Heroku 将自动为您运行 migrate。 - Daniel Roseman
1个回答

7

本地迁移完成后,您应该在<your django app>/migrations文件夹中有迁移文件。例如(这里是我的django应用程序restapi):

/Django/app/folder/restapi/migrations$ ls
0001_initial.py  0001_initial.pyc  __init__.py  __init__.pyc

所以你需要手动提交迁移文件:

heroku$ git commit restapi/migrations/0001_initial.py -m "migrations file"
heroku$ git push heroku master

注意: Heroku不会自动运行您的应用程序迁移!我已经核实了这一点! 在您推送文件后,您应该为您的应用程序运行迁移:
heroku$ heroku run python manage.py migrate restapi 运行中的python manage.py migrate restapi连接到终端... up, run.4602 要执行的操作: 应用所有迁移:restapi 运行迁移: 正在应用 restapi.0001_initial... OK

谢谢你的回答。我一直在为这个问题苦恼,因为我的设置文件反映了Heroku的设置,而我还没有创建另一个开发设置文件来在本地运行,然后再推回Heroku。+1! - John Z

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接