I had a app where there were models and that site I have deployed. Now I have added 2 models in the app. Unfortunately my migration was deleted in local and after adding the models I again generated the migration with 2 new models.
It gives me 0001_initial.py where I can see my new models too. Now I updated my this file in server. But when I did python manage.py migrate it says "Some of your model has been changed but not reflected so do manage.py makemigrations and manage.py migrate"
I tried "python manage.py migrate" but it says same thing. I am unable to get these models. I have even tried "python manage.py syncdb" but same error.
I have registered these models in admin so in admin I am seeing these models but when I click it my servers get hang. I think because my models are not synchronised or my new tables are not created.
In my migration i can see the new models too but when I do "manage.py migrate" i get errors that I should migrate first and re-migrate.
Is there anyway so that I can compel my app to use that migration forcefully where I have my new models too.
I am trying this from hours but no solution. Need help
Related
Recently I'm doing a small Django project that I have to work with my teammates,
so I clone the project's repository from github.
The problem is , the database in my computer doesn't have the table so i think i have to makemigrations and migrate it. But after i did that,django only createed its own tables but didn't create other tables that my teammates wrote in Django's models.
I really need your guys hlep
this are the models my teammates wrote
but after i makemigrations and migrate it ,phpmyadmin does not show the tables i want
makemigrations and migrate
the picture on phpmyadmin after I migrate django models
This is my settings
after tried this,it still not working
migrations folder
You should use managed=True in all models for managing the migrations via django
run
python manage.py makemigrations *name_of_you_app_that_has_models_here*
python manage.py migrate *name_of_you_app_that_has_models_here*
I've got a Django application which has been happily humming along now for quite some time (2 years or so).
It's on 3.0.10 currently - when I tried to upgrade to 3.1.3, it says there was a migration for the auth application. No worries! Never been an issue before...
I ran python manage.py migrate and got the following error:
"Cannot find the object "auth_user" because it does not exist or you do not have permissions."
Which, I suppose would be true because we do not have a User model at all in this application. There is no auth_user table, that is correct. In other apps we have an AbstractUser that routes to a table named: org_user - but again:
this particular app (and project) do not have any User model associated with them
Obviously this (apparently, now) leads to some issues.
Any thoughts on how to get around this? I thought about removing auth from installed apps and tried that but it led to more issues when trying to runserver.
You can fake a migration using --fake option:
python manage.py migrate --fake auth
python manage.py migrate
But I suspect the error you get could be symptomatic of a project design issue, such as not setting properly settings.AUTH_USER_MODEL
Solution 1 :- Run these commands :-
python manage.py migrate auth
python manage.py migrate
Solution 2 :- Try to copy your Project in another folder and then run migrations.
I was working on models in django and after creating classes for models and when migrating them I was supposed to use three commands for completing migration of models. The commands are :python manage.py migrate,python manage.py makemigrations <app_name>,python manage.py migrate
So my question is that why should we use three commands like this ?
From the django docs,
migrate: which is responsible for applying and unapplying migrations.
makemigrations: which is responsible for creating new
migrations based on the changes you have made to your models.
If you make changes to your model use python manage.py makemigrations followed by python manage.py migrate.
Incase of initial migration just after you create an app you dont need to python manage.py makemigrations but just python manage.py migrate works.
I deleted two models from models.py, and when I run makemigrations and migrate locally, everything is fine. When I run makemigrations on Heroku, I get the following message, where Building and BuildingInstance are the models I deleted:
Migrations for 'hello':
0002_building_buildinginstance.py:
- Create model Building
- Create model BuildingInstance
When I run migrate, I get:
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.
I followed the steps here and also tried squashing the migrations locally and on Heroku as suggested here. How can I fix this problem?
As I have written many times here, you must not run makemigrations on Heroku. Run it locally, commit the result, and then​ run migrate on Heroku.
I've created a new Django project consisting of a single app. I thought Django would only migrate an app only if its migrations exist.
The first time I run python manage.py migrate, Django would create tables for my app as well(I've created models.py for my app)
I haven't run python manage.py makemigrations app or python manage.py makemigrations till this time.
I would get the following output on running python manage.py migrate:
Synchronizing apps without migrations:
Creating tables...
Creating table app_model
This is not what I want, because the next time I actually make migrations for the app and run migrate, Django would complain that the tables already exist.
You can create the migrations, and fake the first migration:
python manage.py makemigrations <app_name>
python manage.py migrate --fake-initial
This will skip any initial migration for which the tables have already been created.
Django (pre 1.9) will synchronize any apps that don't have migrations, see the docs on migrate:
The behavior of this command changes depending on the arguments provided:
No arguments: All migrated apps have all of their migrations run, and all unmigrated apps are synchronized with the database,
If you want to save migrations for app, wich you already migrate. You can change one field in model, then makemigrations this_app -> migrate and return has been again with makemigrations and migrate. But I dont understand why you want this.