Django 1.7 makemigrations没有效果

时间:2014-11-20 20:11:41

标签: django database-migration heroku-postgres django-1.7 django-migrations

我一直在我的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和迁移的了解已经足够危险了,所以我想我会在这里问。有没有人遇到过这个?

1 个答案:

答案 0 :(得分:7)

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

/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会自动在你的app上运行迁移!我检查了这个! 在推送文件后,您应该为您的应用运行迁移:

heroku $ heroku运行python manage.py迁移restapi 运行连接到终端的python manage.py migrate restapi ...运行,运行.4602 执行的操作:   应用所有迁移:restapi 正在运行迁移:   应用restapi.0001_initial ...确定