I'm currently working on Django project. Inside it I have an application 'Basketball'. That app have models such as 'Team', 'Player' and others. I've put my project on Heroku.
My problem is that I can access data in 'Basketball' models only by Django ORM. When I use raw SQL database doesn't see my tables.
To show an example, when I use Django shell of my project on Heroku
:~/$ heroku run python3 manage.py shell
>>> from Basketball.models import Player
>>> players = Player.objects.all()
Variable 'players' indeed contains all instances of 'player' model. When I explore database through Heroku command line
:~/$ heroku pg:psql
And when I list all tables
my_project::DATABASE=> \dt
I get following output:
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 | **************
But when I try to execute
my_project::DATABASE=> SELECT * FROM Basketball_player;
I get
ERROR: relation "basketball_player" does not exist
LINE 1: SELECT * FROM Basketball_player;
When I do makemigrations on my project on Heroku
:~/$ heroku run python3 manage.py makemigrations
It makes some migrations
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
But when I try to apply them
:~/$ heroku run python3 manage.py migrate
That messages shows
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.
makemigrationscreates migration files on disk to be run withmigrate. But on Heroku the disk is ephemeral, files do not persist between runs. As I said, you must create the migration files locally and upload to Heroku before running migrate.makemigrationswhile was thinking aboutmigrate. Thanks!