Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python迁移将Heroku Django应用程序的新模型表添加到远程Heroku Postgres?_Python_Django_Postgresql_Heroku - Fatal编程技术网

如何使用Python迁移将Heroku Django应用程序的新模型表添加到远程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应用程序上基于现有代码创建了一个新模型,方法是复制和粘贴现有模型及其表的函数和文件。但我很难让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