Django 1.7 on Heroku: how do I get makemigrations to rescan the database? - django

I have Django 1.7 running on Heroku. I've made a change to the models.py file (added a column to a table) but Django doesn't seem to be able to detect this. When I run
python manage.py makemigrations appname
it responds No changes detected in app.
I've tried deleting the appname/migrations folder, but that doesn't help.
Is there a way to get Django to rescan the database and check for differences? This was easy with South.

https://docs.djangoproject.com/en/1.7/topics/migrations/#the-commands
Have you tried
python manage.py migrate
It seems the migrate is "responsible for applying migrations, as well as unapplying and listing their status."

Related

relation "django_admin_log" already exists

when i try to run python manage.py migrate i run into following error
Upon running python manage.py run migrations it says no changes detected. and when i runserver it gives me warning that i have unapplied migrations as well.i have been searching internet for two hours but got not solution. Someone knowing the solution please share :)
The table in your database that stores migration data to keep track of what has been applied is out of date. Try running python manage.py migrate --fake
Try python manage.py makemigrations [app name] and if still, this does detect changes then delete the folder named migrations which is inside your application folder and then use this python manage.py makemigrations [app name]. Once migration happens successfully do the python manage.py migrate.
Don't Try This at Home
I faced this issue, i make two changes,
change AUTH_USER_MODEL, so i have one migraiton about it
second one add new field for my folder_model(migration name: folder_model 0021)
When my first migrate attempt(I already run makemigrations commands on local so i have migration files), it says;
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency account.0001_initial on database 'default'
This error reiases because i change the AUTH_USER_MODEL in the middle of the project, normally you have to remove your database and fresh start from the beginnig(also truncate migrations etc.), according to Django doc -> https://code.djangoproject.com/ticket/25313
To fix this issue, you don't have to delete all migrations on db, just delete the migrations about admin(not from project just database)
After that just run
python manage.py migrate
It throws relation "django_admin_log" already exists. For this issue, run:
python manage.py migrate --fake
That's it, but not completely. Make fake migration act like you already make your all migrations successfully and save these on db. The issue came here that i have another migration about folder_model 0021 and with fake migration it doesn't applied to my database table but saved to db_migrations table.
So fix this issue, delete the folder_model 0021to database migration table (just 0021 not all folder_model migrations).
After delete just run python manage.py migrate
Everything is fine!

InconsistentMigrationHistory with django user_auth

I'm working on my first django project and I'm trying to add user_authentication now. I know i probably should've done this at the very start but I'm trying to do it now. I have a few other apps created and its running fine. However when I added an accounts app i get the following error when i run migrations in accounts/models.py
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency accounts.0001_initial on database 'default'.
What helped me with migrations in situation where I have problem like:
django.db.utils.ProgrammingError: (1146, "Table 'mydjango.MyApp_publication' doesn't exist").
It's regarded to the connections.py is following:
Run the command python manage.py
migrate --fake MyApp zero
and then python manage.py migrate MyApp.
Here 'MyApp' is the app you're creating on your Django Server.
I delete all tables except ‘auth_user’, and run ‘python manage.py makemigrations myapp’ ‘python manage.py migrate myapp’ again.
This solved the problem.

Reset Django registration models?

I am trying to implement django registration-redux 1.2. I installed the application and added to it settings.py of my project. I ran manage.py syncdb as well as makemigrations/migrate. Typing these commands again and I get no changes detected. However it seems like the tables are not getting created. When I try to register I get the following error:
ProgrammingError at /main/register/ (1146, "Table 'la_test_serve.registration_registrationprofile' doesn't exist")
Is there a way to reset the project/app so that these tables get created?
Thanks,
Robert
Try to run schemamigration for your registration apps
python manage.py schemamigration registration --initial
after that run migrate
python manage.py migrate registration
Remove the app from your "INSTALLED APPS" setting. Then run manage.py makemigrations and manage.py migrate. Reinstall the app.
Note: If you didn't add 'registration' (yes, simply 'registration') to your "INSTALLED APPS", it won't work.
I found this error occurred when I was reinstalling django-registration-redux.
Either way, check that you have deleted not only the table for registration in the database but also ensure that in the migrations table delete the corresponding row, in this case 'registration'.

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

How to get my database to reflect changes made to models.py?

I made a change to my models, and I cannot for the life of me figure out how to get my database to reflect my models. So far I have tried the following:
python manage.py shelldb
SELECT * FROM sqlite_master WHERE type='table';
DROP TABLE appname_modelname;
When I tried that I got: "unknown command: shelldb".
I also tried:
python manage.py dbshell
DROP TABLE accounts_userreview;
No error, but my db still doesn't reflect my models.
Finally, I just altogether deleted my database by dragging it into the trash and then doing syncdb, it then made me create a new superuser, but STILL the database that was created does not reflect the changes to my models.
I'm at a loss here, What else can I do here? Also, I'm new to learning Django, is there some kind of layer in between the models and my database? I would assume there is since deleting and then rebuilding the database didn't work.
Would appreciate any advice here.
if you are on Django < 1.7 , you have to use some migration tool i.e. - South . Django 1.7 has inbuilt migration.
For more info migrations
Run these commands in terminal to make migrations for Django 1.7
python manage.py makemigrations
python manage.py syncdb
for Django < 1.7
use South