Django migrations not pushing to Heroku - django

I have updated a Django blog to use slug urls <slug:slug>/ instead of id <int:pk>/. I also added a slugField to the Article model, and converted all hrefs to article.slug. Ran migrations and everything worked fine locally. However, when I pushed to Heroku I got an error.
This is what happens when I attempt to save a new article.
ProgrammingError at /admin/articles/article/
column articles_article.slug does not exist
LINE 1: ...ticles_article"."id", "articles_article"."title", "articles_...
^
Request Method: GET
Request URL: https://***********.herokuapp.com/admin/articles/article/
Django Version: 2.1.4
Exception Type: ProgrammingError
Exception Value:
column articles_article.slug does not exist
LINE 1: ...ticles_article"."id", "articles_article"."title", "articles_...
^
I checked my Heroku Postgress database and I found that the new slug column hadn't been added even though I did migrations. I'm not exactly sure what to do next. I'm currently searching for ways to manually update the heroku postgress, but if there's a less invasive way to solve this problem I'm all ears.

first verify that the migration was executed (heroku)
verify that the last migration of the article model is in the django_migrations table
In case you can't find it, make sure you have updated migrations (local)
python manage.py makemigrations
run the migration in db production (heroku)
heroku run python manage.py migrate

Did you happen to make migrations first then migrate? It's noted backward in your comment above. Also, are you sure you applied the migrations to your production database? It requires a settings flag added to the migrate command to point to your production settings/db location.

Related

django CMS error cms_urlconfrevision on deployment

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

PostgreSQL Django migrate error - domain already exits

I've set up a new Django project (based on the template django cookie cutter) but get a postgres error when trying to migrate the database for the first time
psycopg2.ProgrammingError: relation "django_site_domain_a2e37b91_uniq" already exists
I'm not clear what the issue is or how best to diagnose?
What is SITE_ID?
Django was created from a set of scripts developed at a newspaper to
publish content on multiple domains; using one single content base.
This is where the "sites" module comes in. Its purpose is to mark
content to be displayed for different domains.
In previous versions of django, the startproject script automatically
added the django.contrib.sites application to INSTALLED_APPS, and when
you did syncdb, a default site with the URL example.com was added to
your database, and since this was the first site, its ID was 1 and
that's where the setting comes from.
Keep in mind that starting from 1.6, this framework is not enabled by
default. So if you need it, you must enable it
The SITE_ID setting sets the default site for your project. So, if you
don't specify a site, this is the one it will use.
Ways to fix this:
Increment SITE_ID:
1. Increment `SITE_ID` variable in settings.py
2. python manage.py makemigrations
3. python manage.py migrate --run-syncdb
Cons: Had to increment SITE_ID without good reason
Attempt to migrate without --run-syncdb:
1. python manage.py makemigrations
2. python manage.py migrate
Note: May have to try multiple times before it works. Unsure why, possibly because I was in the process of deleting the pvc

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

heroku - DatabaseError: relation "south_migrationhistory" does not exist

i purchased an outsource service to develop a web site in django to be deployed in heroku and AWS S3 (boto package).
Unfortunately the developer did not comment the code, despite it was asked, and left the project uncompleted for following up with a bigger client.
I've hired another django 'expert' to fix a part which was not developed, and he want to (over)charge for deployment testing, which i think should be a normal matter for good practices! i am working on my own budject, and need to work it out myself.
I was able to make the project run locally and make myself the frontend templates which were not fully developed, but I am having issues in deploying the code on my own staging environment.
I set up a staging environment under my credential to check if everything is ok, before pushing to production.
I think I almost get there, though:
heroku run python manage.py migrate --all --noinput --app my-app-staging
generate in the console:
Running `python manage.py migrate --all --noinput` attached to terminal... up, run.4833
DatabaseError: relation "south_migrationhistory" does not exist
LINE 1: ...gration", "south_migrationhistory"."applied" FROM "south_mig...
In the browser:
DatabaseError at /
relation "django_site" does not exist
LINE 1: ..."django_site"."domain", "django_site"."name" FROM "django_si...
^
Request Method: GET
Request URL: http://my-app-staging.herokuapp.com/
Django Version: 1.5.6
Exception Type: DatabaseError
Exception Value:
relation "django_site" does not exist
LINE 1: ..."django_site"."domain", "django_site"."name" FROM "django_si...
^
Exception Location: /app/.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py in execute, line 5
I checked my settings and they look ok:
i check AWS S3 bucket and it is able to write there;
settings in heroku console display that the db has been created.
I followed:
Heroku created table but when I'll migrate, he says that doesn't created
but it looks my locals.py are ok too, and in my local git branch .gitignore will exclude db.sqlite
My git and heroku ssh keys have been generated and added, so i dont' think it is an issue of authentification.
How could i check that the db is properly connected to django project and I am not invalidated?
Could you please help in debriefing to understand what this error means and how to solve it?
So much thank you.
It sounds like you might not have created the initial South migration tables on your staging server. This is actually done using syncdb:
Once South is added in, you’ll need to run ./manage.py syncdb to make the South migration-tracking tables (South doesn’t use migrations for its own models, for various reasons).
To run this on Heroku, you'll probably want to use something like
heroku run python manage.py syncdb
Once this is done, you should be able to move forward with the South commands.

South not Migrating django.contrib.admin

I have a Django project that's managed by South. I ran through the normal procedure when I first started the project:
Install South
Add South to INSTALLED_APPS
Perform initial syncdb
schemamigration --initial, followed by migrate myapp
Everything's been working fine and I've done several migrations since. Now I enabled the django admin portion of the site (INSTALLED_APPS, urls, etc.). When I tried adding a test user, I was received the following error:
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/auth/user/add/
Django Version: 1.4.3
Exception Type: DatabaseError
Exception Value:
no such table: django_admin_log
I tried running schemamigration myapp --auto but it's telling me nothing's changed. I even tried running convert_to_south django.contrib.admin, as well as trying a fake migration, but I keep getting the same error. Any help is appreciated.
second's answer is correct
only apps that make use of south will be managed by south
so using south isn't a possible solution.
Your issue is that the syncdb thinks that the table for django_admin_log has already been created.
Solution
open your django_content_type table.
delete the record for the name="log entry", app_label="admin", model="logentry" content type.
run syncdb again
only apps that make use of south will be managed by south
django.contrib.admin doesn't. instead you need another syncdb (it will leave any existing tables alone, so should be safe to run)