チュートリアルで使用されていたheroku run python manage.py migrate
を実行して、リモートのHeroku Postgresデータベースに実際に新しいテーブルを作成したかったのです。しかし、それはバットからすぐには機能しませんでした。私がする必要があったのは、いくつかのPythonファイルをセットアップし、最後にそのコマンドを実行することでした。
これは、新しいフィールドの追加など、モデルを編集する場合にも機能します。
私が追加されたすべてのファイルがthis tutorial
に基づいてHeroku tutorial's codeにしているこれは私がやったまさにです:hello/models.pyで
、
class Mytable(models.Model):
when = models.DateTimeField('date created', auto_now_add=True)
はPythonが生成してみましょう追加0002_mytable.py
私のローカルhello/migrations
のファイルをMacで次のコマンドを実行してください(virtualenvのHerokuのにしてログインした)ターミナル:
python manage.py makemigrations hello
と私は、この応答得た:
Migrations for 'hello':
0002_mytable.py:
- Create model Mytable
を私のリモートHerokuの
git add hello/migrations/0002_mytable.py
git commit -am "added new migration file"
git push heroku master
- にこの新しいマイグレーションファイルを追加します。
HerokuはリモートのHeroku Postgresでテーブルをリモート作成します。
heroku run python manage.py migrate
あなたは見るべき
Running python manage.py migrate on ⬢ your-heroku-url... up, run.1699
Operations to perform:
Apply all migrations: admin, contenttypes, hello, sessions, auth
Running migrations:
Rendering model states... DONE
Applying hello.0002_mytable... OK