如何使用Python迁移将Heroku Django应用程序的新模型表添加到远程Heroku Postgres?
在成功完成关于的教程后,我在Heroku应用程序上基于现有代码创建了一个新模型,方法是复制和粘贴现有模型及其表的函数和文件。但我很难让Heroku在Postgres上远程创建表格。经过反复试验,我找到了下面的答案如何使用Python迁移将Heroku Django应用程序的新模型表添加到远程Heroku Postgres?,python,django,postgresql,heroku,Python,Django,Postgresql,Heroku,在成功完成关于的教程后,我在Heroku应用程序上基于现有代码创建了一个新模型,方法是复制和粘贴现有模型及其表的函数和文件。但我很难让Heroku在Postgres上远程创建表格。经过反复试验,我找到了下面的答案 设置:Heroku Python正在本地和远程运行,Heroku Postgres只在远程运行。我想通过运行教程中使用的Heroku run Python manage.py migrate,在远程Heroku Postgres数据库上创建我的新表。但它并没有立刻起作用。我需要做的是设
设置:Heroku Python正在本地和远程运行,Heroku Postgres只在远程运行。我想通过运行教程中使用的Heroku run Python manage.py migrate,在远程Heroku Postgres数据库上创建我的新表。但它并没有立刻起作用。我需要做的是设置一些Python文件,然后在最后运行该命令 如果您也编辑模型,例如添加新字段,则此操作也有效 我添加的所有文件都是基于 这正是我所做的: 在中,添加 让Python在我的本地hello/migrations中生成0002_mytable.py文件,方法是在登录到Heroku和virtualenv的Mac终端上运行以下命令:
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
我想通过运行教程中使用的Heroku run python manage.py migrate,在远程Heroku Postgres数据库上创建新表。但它并没有立刻起作用。我需要做的是设置一些Python文件,然后在最后运行该命令 如果您也编辑模型,例如添加新字段,则此操作也有效 我添加的所有文件都是基于 这正是我所做的: 在中,添加 让Python在我的本地hello/migrations中生成0002_mytable.py文件,方法是在登录到Heroku和virtualenv的Mac终端上运行以下命令:
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