Postgresql没有看到Django(Heroku)的模型

时间:2015-12-19 01:13:45

标签: python django postgresql heroku

我目前正在研究Django项目。在里面我有一个应用程序' Basketball'。该应用拥有“团队'播放器”等模型。和别的。我把我的项目放在了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.

0 个答案:

没有答案