![](/img/trans.png)
[英]Why isn't Heroku's Postgresql updating according to Django's models.py?
[英]Postgresql doesn't see models from Django(Heroku)
我目前正在从事Django项目。 在它里面,我有一个应用程序“篮球”。 该应用具有“ Team”,“ Player”等模型。 我已经将项目放在Heroku上了。
我的问题是我只能通过Django ORM访问“篮球”模型中的数据。 当我使用原始SQL数据库时,看不到我的表。
举例来说,当我在Heroku上使用项目的Django Shell时
:~/$ heroku run python3 manage.py shell
>>> from Basketball.models import Player
>>> players = Player.objects.all()
变量“玩家”确实包含“玩家”模型的所有实例。 当我通过Heroku命令行浏览数据库时
:~/$ heroku pg:psql
当我列出所有表格时
my_project::DATABASE=> \dt
我得到以下输出:
List of relations
Schema | Name | Type | Owner
--------+----------------------------+-------+----------------
public | Basketball_contract | table | **************
public | Basketball_match | table | **************
public | Basketball_matchstats | table | **************
public | Basketball_player | table | **************
public | Basketball_roster | table | **************
public | Basketball_team | table | **************
public | auth_group | table | **************
public | auth_group_permissions | table | **************
public | auth_permission | table | **************
public | auth_user | table | **************
public | auth_user_groups | table | **************
public | auth_user_user_permissions | table | **************
public | django_admin_log | table | **************
public | django_content_type | table | **************
public | django_migrations | table | **************
public | django_session | table | **************
public | postman_message | table | **************
但是当我尝试执行
my_project::DATABASE=> SELECT * FROM Basketball_player;
我懂了
ERROR: relation "basketball_player" does not exist
LINE 1: SELECT * FROM Basketball_player;
当我在Heroku上的项目上进行迁移时
:~/$ heroku run python3 manage.py makemigrations
它进行了一些迁移
Migrations for 'Basketball':
0001_initial.py:
- Create model Contract
- Create model Match
- Create model MatchStats
- Create model Player
- Create model Roster
- Create model Team
- Add field team to roster
- Add field player to matchstats
- Add field away to match
- Add field home to match
- Add field player_signed to contract
- Add field team to contract
但是当我尝试应用它们时
:~/$ heroku run python3 manage.py migrate
该消息显示
Operations to perform:
Synchronize unmigrated apps: staticfiles, mathfilters, django_countries, messages
Apply all migrations: auth, sessions, admin, contenttypes, postman
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
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.
在PostgreSQL中,当您使用大写字母时,必须用引号将它们括起来,因此应该
SELECT * FROM "Basketball_player"
代替
SELECT * FROM Basketball_player
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.