django CMS error cms_urlconfrevision on deployment - django

I'm trying to deploy a django CMS app to PythonAnywhere or Heroku but I keep getting this error on Heroku:
ProgrammingError at /
relation "cms_urlconfrevision" does not exist
LINE 1: ...sion"."id", "cms_urlconfrevision"."revision" FROM "cms_urlco...
and this error on PythonAnywhere:
OperationalError at /
no such table: cms_urlconfrevision
The app works fine on localhost.
I understand it's a database table missing but I have no idea how to fix it. I tried removing all the migration files and .pyc files and migrated again, I removed the database, I tried migration with --fake. Nothing seems to work.
I'm using
django-cms==3.6.0
Django==2.1.8

I understand it's a database table missing but I have no idea how to fix it. I tried removing all the migration files and .pyc files and migrated again, I removed the database, I tried migration with --fake. Nothing seems to work.
Migration files just define what migrations exist. They don't modify your database by themselves. There are two steps here:
Creating migrations with makemigrations. This should only be done on your development machine. By the time your code is being deployed you shouldn't have any model changes that would cause new migrations to be generated.
Applying migrations to your database with migrate. This must be done in development (to update your local database) and also in production (to update your production database).
On Heroku, you'd run your migrations with
heroku run python manage.py migrate
I think this is the step you're missing.

Hello maybe you found the solution but if the is somebody coming across that issue, it due to the database settings.
In project_name/site_name/settings.py and database settings section
Change
NAME: 'project.db'
to
NAME:'project_name/project.bd'

in the file setting.py change
'NAME': 'project.db',
to
'NAME': BASE_DIR / 'project.db',
worked for me

Related

django.db.utils.ProgrammingError: (1146, "Table 'main.socialaccount_socialapp_sites' doesn't exist")

I'm trying to implement Google Login on my Django production website. It works fine on development server, but on my production server, I face this issue after having run python manage.py migrate. I'm not sure what to do, I already tried deleting all the migrations and re-running makemigrations and migrate.
Checklist
run showmigrations to see which migrations are done.
if the relevant migration containing the table appears to be migrated, rollback and run migrate again.
when you want to regenerate migration files, you need to first rollback while you have the old migration files.
if you'd like to check which tables exist, use dbshell or other shell depending on the database you're using.
Other things
I would not recommend regenerating migration files just because there is some db issue.

Heroku Django postgres migration merge: psycopg2.errors.DuplicateTable: relation already exists

This is a Heroku-specific issue with a Django project 1.11.24 running Python 3.6.5 and a Heroku postgres database.
During testing of two different branches during development, different conflicting migration files were deployed at different times to the Heroku server. We recognized this, and have now merged the migrations, but the order the Heroku psql db schema was migrated is out of order with the current migration files.
As a result, specific tables already exist, so on deploy applying the updated merged migration files errs with:
psycopg2.errors.DuplicateTable: relation "table_foo" already exists
In heroku run python manage.py showmigrations -a appname all of the migrations are shown as having run.
We've followed Heroku's docs and done the following:
Rolled back the app itself to before when the conflicting migrations took place and were run (https://blog.heroku.com/releases-and-rollbacks)
Rolled back the postgres db itself to a datetime before when the conflicting migrations took place and were run (https://devcenter.heroku.com/articles/heroku-postgres-rollback)
However, despite both app and db rollbacks, when we check the db tables themselves in the rollback in pql shell with \dt, the table causing the DuplicateTable err still exists, so the db rollback doesn't actually seem to effect the django_migrations table.
It's Heroku, so we can't fake the migrations.
We could attempt to drop the specific db tables that already exist (or drop the entire db, since it's a test server), but that seems like bad practice. Is there any other way to address this in Heroku? thanks
I eventually fixed this by manually modifying migration files to align with the schema dependency order that was established. Very unsatisfying fix, wish Heroku offered a better solution for this (or a longer postgres database rollback window)

"django.db.utils.ProgrammingError: relation "auth_user" does not exist" Django V2.0

I've recently upgraded Django to V2.0 and I'm unable to make migrations due to the following error:
django.db.utils.ProgrammingError: relation "auth_user" does not exist
I know a similar bug existed in V1.8 which I fixed by migrating the model which others depend on, i.e. auth_user and then the rest:
python manage.py migrate auth
python manage.py migrate
When I try to migrate 'auth' I encounter the same error. Has anybody encountered/found a solution to this?
I encountered the same error.
At last I found the root cause was the database.
There may be some auth info in the database already.
Editing setting.py and using another new database will solve this problem.
I have same issue even after creating new database.
What helped me, is choosing another owner, when creating new DB, not postgress owner. Also I was using
py manage.py migrate myapp
with this command, I have the same issue as well
But when I tried use
py manage.py migrate
and change owner from postgress on DB creating, it helped!
I ran into the same problem after I upgraded my DB with new/removed apps and forgot to upgrade my asgi.py and wsgi.py files to point to the upgraded settingsprod.py (for anyone who was following along with the eCommerce CodingWithStein). I then had to restart my nginx and gunicorn services.

Django: Heroku deploy not migrating properly

I'm new to Heroku and I am trying to do my first deploy with a change in my models. Now I already have some important stuff in my app's database that I don't want to lose (I'm using PostgresSQL).
Anyway, I did those few improvement to my app's model and it works alright locally, but when I try to deploy it just gives me the
Internal Server Error: /lares/
ProgrammingError at /lares/
column lares_imovel.referencia does not exist
I am used to throwing makemigrations and migrate locally and than just git push heroku master
Anyway, I also tried the heroku run python manage.py migrate afterwards, but I get the same result every time.
I deleted all my migrations files and created them again for this particular app, still it works locally and the issue remains on production.
Do you guys have any idea why this is happening?
I don't know if any of my code is necessary, I'm pretty sure the problem is not there, but if requested I can post it here.
Thanks!

django - schema migration - how to add a field

I have a django 1.8 app working with a db.
I'm trying to change the schema of a table using the built-in migration.
Here are the steps I did:
In my dev invironment, I grabbed the app source and ran
python manage.py sycdb
then I ran
python manage.py loaddata ~/my_data.json
then I modified modes.py. Added a field and renamed a field...all from the same table 'TABLE1' which had no data.
then
python manage.py makemigrations myapp
python manage.py migrate
Error: django.db.utils.OperationalError: table "myapp_someother_table" already exists
then ran
python manage.py migrate --fake-initial
worked!
but when I browsed to the admin page for TABLE1, I get this error:
OperationalError: no such column: myapp_table1.my_new_field_id
I checked the db and yes, there is no such column.
How can I procceed from here? I prefer to fix this via django.
If I fix it straight in the db, then the migration goes out of sync.
Migrations do not automagically see that you have made changes. Migrations detect changes by comparing the current model with the historical model saved in the migration files.
In this case, you didn't have any historical models, since you didn't have any migrations. Django was not able to detect any changes in your models, even though they were different from your database.
The correct way to make changes to your model is to first run manage.py makemigration <my_app>, and then make the changes to your model, followed by another manage.py makemigrations.
You might not be able to do it via pure django and keep your data. I don't have personal experience with south but there are a lot of mentions if this tool. Just in case if nothing else works for you...
Here is what I did to make things work, but there must be a better way so please add more answers/comments...
I deleted the sqlite db and the migration folder
I made the desired changes to model.py
ran syncdb
ran loaddata to load the json data dump that I had saved previously.
just started the dev server