Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

“Programming Error” with /admin/generator DB content when deployed on Heroku #66

Closed
enoren5 opened this issue Jan 10, 2021 · 13 comments

Comments

@enoren5
Copy link
Owner

enoren5 commented Jan 10, 2021

I’m experimenting with swapping different PostreSQL DB instances in and out on Heroku. I’ve got one instance for Lorem Ipsum content and the other instance for meaningful, quality blog content. The first DB was provisioned by a previous freelancer which works well. It is populated with placeholder content.

Now I am trying to spawn a fresh DB from scratch and reconfigure. I’ve got it mostly set up but Django is throwing a Programming Error and I have no clue why. Here is the full error. Here is the main description of the error:

ProgrammingError at /admin/generators/generator/
relation "generators_generator" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "generators_generator"

So far I’ve used Heroku’s official doc explaining how to set up a PostreSQL DB (specifically the provisioning section). I also read “Managing Add-ons”.

To experiment with this new DB instance today, I also leveraged the console log provided by the previous freelancer for the prior Issue (#57). Here it is.

Here are all the terminal commands I used in sequence in a pastebin. As you can see in there, I made a deliberate effort to migrate and make migrations (twice).

What am I missing?

edit: grammar correction

@UmarGit
Copy link
Contributor

UmarGit commented Jan 14, 2021

Hey @enoren5,

The origin of this error is because there is no table named generators_generators exists. This is happening because, we need to create tables of every app in heroku environment. We can achieve this by executing some commands below:

Generally in dijango ( heroku ) we can achieve this by executing heroku run python manage.py migrate and heroku run python manage.py makemigration

But for the nested app like essays, generators, landings: We need to manually add them one by one in heroku as:
heroku run python manage.py migrate essays
heroku run python manage.py migrate generators
heroku run python manage.py migrate landings
heroku run python manage.py makemigration

After running above commands, they will create the required tables, and next you need to add at least one entry for all of the required field in admin interface.

After that, the app will execute as smooth as butter

That's All !

Best Regards,
Umar Ahmed

@enoren5
Copy link
Owner Author

enoren5 commented Jan 14, 2021

Thanks, @UmarGit for the reply.

Yes, I realize that the tables are not yet created. Below are the commands you suggested along with their output. The missing tables remains a problem when trying to add content in the Admin Dashboard.

I tried your commands both locally and remotely. For example, I used heroku run prepended to all the manage.py commands. That didn't resolve the issue. I also logged into heroku in my shell and tried similar commands. That didn't resolve the issue either.

Here it is:

(venv) $ heroku login
heroku: Press any key to open up the browser to login or q to exit: 
Opening browser to https://cli-auth.heroku.com/auth/cli/browser/<hash>
Logging in... done
Logged in as warden496@protonmail.com

(venv) $ heroku run python manage.py makemigrations
Running python manage.py makemigrations on ⬢ tarot-juicer-next-iter... up, run.9439 (Hobby)
No changes detected

(venv) $ heroku run python manage.py migrate essays
Running python manage.py migrate essays on ⬢ tarot-juicer-next-iter... up, run.1603 (Hobby)
CommandError: App 'essays' does not have migrations.

(venv) $ heroku run python manage.py migrate generators
Running python manage.py migrate generators on ⬢ tarot-juicer-next-iter... up, run.6268 (Hobby)
CommandError: App 'generators' does not have migrations.

(venv) $ heroku run python manage.py migrate landings  
Running python manage.py migrate landings on ⬢ tarot-juicer-next-iter... up, run.7583 (Hobby)
CommandError: App 'landings' does not have migrations.

(venv) $ heroku run python manage.py makemigrations    
Running python manage.py makemigrations on ⬢ tarot-juicer-next-iter... up, run.8004 (Hobby)
No changes detected

Here is me logging in remotely and then executing the same commands you recommended:

(venv) $ heroku ps:exec
Establishing credentials... done
Connecting to web.1 on ⬢ tarot-juicer-next-iter... 

(remote) ~ $ python manage.py migrate
Operations to perform:
  Apply all migrations: accounts, admin, auth, contenttypes, sessions
Running migrations:
  Applying accounts.0001_initial... OK
  Applying accounts.0002_passphrase... OK
  Applying accounts.0003_auto_20201203_1609... OK
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying sessions.0001_initial... OK

(remote) ~ $ python manage.py makemigrations
No changes detected

(remote) ~ $ python manage.py migrate essays generators landings
usage: manage.py migrate [-h] [--noinput] [--database DATABASE] [--fake]
                         [--fake-initial] [--plan] [--run-syncdb] [--version]
                         [-v {0,1,2,3}] [--settings SETTINGS]
                         [--pythonpath PYTHONPATH] [--traceback] [--no-color]
                         [--force-color]
                         [app_label] [migration_name]
manage.py migrate: error: unrecognized arguments: landings

(remote) ~ $ python manage.py migrate essays
CommandError: App 'essays' does not have migrations.

(remote) ~ $ python manage.py migrate generators
CommandError: App 'generators' does not have migrations.

(remote) ~ $ python manage.py migrate landings
CommandError: App 'landings' does not have migrations.

(remote) ~ $ python manage.py migrate accounts
Operations to perform:
  Apply all migrations: accounts
Running migrations:
  No migrations to apply.

(remote) ~ $ python manage.py makemigrations
No changes detected

(remote) ~ $ 

@UmarGit
Copy link
Contributor

UmarGit commented Jan 15, 2021

Hey @enoren5,

I don't know why those commands are not executing. So, I found out a new method to open up bash in heroku using command heroku run bash -a your-app-name

I simply executed the below listed commands, you can see, how the apps are migrated.

PASTE BIN

Now the app is healthy and perfectly working.

That's all I had done !
Best Regards,
Umar Ahmed

@enoren5
Copy link
Owner Author

enoren5 commented Jan 15, 2021

Hi @UmarGit! Thank you for fixing it but I can't tell the difference between the commands you entered compared to the commands I entered. Would you be able to tell me what you did differently?

Also: I am desperately trying to make sense of your commands which is almost impossible for me because your shell is not color coded. So could you please share your code in a pastebin for me to inspect further?

@UmarGit
Copy link
Contributor

UmarGit commented Jan 15, 2021

Basically the difference is very simple, I forgot the command to migrate apps:

We can migrate an app step by step as:

  1. python manage.py makemigrations _app-name_ << to create models, with a folder named as migrations.
  2. python manage.py migrate << to create tables in the database.

So as a shortcut to execute commands on heroku we can call bash as heroku run bash to open a terminal, then we can execute commands continuously.

Best Regards,
Umar Ahmed

@UmarGit
Copy link
Contributor

UmarGit commented Jan 15, 2021

And migrating apps to heroku throwing error as:

CommandError: App '_app-name_' does not have migrations.

When executing commands on heroku separately as heroku run python manage.py makemigrations _app-name_ is not working, So, instead I just migrate the apps in the bash of heroku ( which I described above )

@enoren5
Copy link
Owner Author

enoren5 commented Jan 15, 2021

But @UmarGit: As you can see I already executed those commands. To reiterate what I said earlier, I already logged in via bash and exectued your commands. To quote my self from earlier: I invoked $ heroku ps:exec which gave me shell access. In the remote environment (as I quoted in my post above) I ran: ~ $ python manage.py migrate generators (which is the same thing I entered). How did you get a different output? The output in my remote shell was: "CommandError: App 'generators' does not have migrations." How did you avoid this error when you and I are running the exact same commands?

@enoren5
Copy link
Owner Author

enoren5 commented Jan 15, 2021

You suggest using $ heroku run bash. I used $ heroku ps:exec which does the same thing. So all my commands on the remote host I quoted above are the same as yours as far as I can tell.

@enoren5
Copy link
Owner Author

enoren5 commented Jan 15, 2021

I just realized the difference. This is what you recommended:
(remote) ~ $ python manage.py makemigrations essays

This is what I did:
(remote) ~ $ python manage.py migrate essays

I was using 'migrate' while you were using 'makemigrations'

I will mark this issue as solved and closed.

Thank you @UmarGit for your patience with the oversight on my part. :)

@enoren5 enoren5 closed this as completed Jan 15, 2021
@enoren5 enoren5 reopened this Jan 15, 2021
@enoren5
Copy link
Owner Author

enoren5 commented Jan 15, 2021

I just realized that in your very first post in this, you had recommended: $ heroku run python manage.py migrate generators which is what I tried. What you had meant to have said was: heroku run python manage.py makemigrations generators So the oversight was on my part and on your part. I am glad this has finally been clarified decisively. 💯

@UmarGit
Copy link
Contributor

UmarGit commented Jan 15, 2021

Yes exactly @enoren5 , Thank you

@UmarGit
Copy link
Contributor

UmarGit commented Jan 15, 2021

But @UmarGit: As you can see I already executed those commands. To reiterate what I said earlier, I already logged in via bash and exectued your commands. To quote my self from earlier: I invoked $ heroku ps:exec which gave me shell access. In the remote environment (as I quoted in my post above) I ran: ~ $ python manage.py migrate generators (which is the same thing I entered). How did you get a different output? The output in my remote shell was: "CommandError: App 'generators' does not have migrations." How did you avoid this error when you and I are running the exact same commands?

The only thing is the sequence of executing of commands:

  1. python manage.py makemigrations _app-name_ < to create models, with a folder named as migrations. ( Must execute first )
  2. python manage.py migrate < to create tables in the database. ( Then execute in last )

@UmarGit
Copy link
Contributor

UmarGit commented Jan 15, 2021

I just realized that in your very first post in this, you had recommended: $ heroku run python manage.py migrate generators which is what I tried. What you had meant to have said was: heroku run python manage.py makemigrations generators So the oversight was on my part and on your part. I am glad this has finally been clarified decisively.

Yes all confusion was created from my side, Sorry for it !
I just forgot the sequence of commands.

@enoren5 enoren5 closed this as completed Jan 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants