42👍
It happens if you ran default auth
app migrations and later changed the AUTH_USER_MODEL
in settings.py
. You can try following:
# comment AUTH_USER_MODEL in settings.py so it points to default User model
python manage.py migrate auth zero
# uncomment to be AUTH_USER_MODEL='recommend.AuthUser'
python manage.py migrate auth
22👍
I delete all the migration files and database and applied it.
Then I could migrate.
- [Django]-Paginate relationship in Django REST Framework?
- [Django]-Django connection to postgres by docker-compose
- [Django]-How to format time in django-rest-framework's serializer?
8👍
Note : I am using sqlite3 as a database.
Hi,
I easily solved it by deleting all the migration files in the migrations folder except the __init__.py
file. And also delete db.sqlite3
. Now run the following commands : python manage.py makemigrations
and then python manage.py migrate
. Now you’ll have to create the super user once again, so for this just type the following commmand : python manage.py createsuperuser
. Then it will prompt for username, email and password, so enter your credentials and all will continue to work properly once again I hope that this will be helpful.
- [Django]-Get the list of checkbox post in django views
- [Django]-Django – SQL bulk get_or_create possible?
- [Django]-Ignoring Django Migrations in pyproject.toml file for Black formatter
2👍
For me helped split on two migration
- create new table (with out connection betwin new and old tables and without
AUTH_USER_MODEL = 'recommend.authuser'
) - add AUTH_USER_MODEL to settins.py and other connections with new table
- [Django]-Django {% if forloop.first %} question
- [Django]-The QuerySet value for an exact lookup must be limited to one result using slicing. Filter error
- [Django]-Django: list all reverse relations of a model
2👍
I had to refer to this stack: to be able to solve that issue.
I simply followed the steps bellow:
Since I am not using sqlite, I made new database configuration that refers to my postgres, in my settings.py:
old database i am not more going to use:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'leszexpert', 'USER': 'postgres', 'PASSWORD': '', 'HOST': '127.0.0.1', 'PORT': '5432', } }
new database I want to start using:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'leszexpert_db', 'USER': 'postgres', 'PASSWORD': '', 'HOST': '127.0.0.1', 'PORT': '5432', } }
As you can see, the difference is the DATABASE NAME (referenced after ENGINE)!!!!!!
- I stopped the server and already previously deleted all existing corresponding migrations.
- I closed my IDE VScode (I have realised from experience that when something does not take effect, after closing it and reopening it, it most time ends up taking effect)
- when I reopened the code editor, I uncomment my models (i commented them previously), then VERY VERY IMPORTANT: DO NOT START OR RUN YOUR SERVER AT THIS POINT. because now you are about to operate on the new database specified above and the issue as you know we are trying to solve is that if you run migration of that type of models after runing the server, it will not create your model…therefore DO NOT RUN SERVER YET
- INSTEAD DO THIS: RUN MIGRATIONS AND THEN MIGRATE
- ET VOILA (French expression to That is it): your extended user model will be created in your database:
Thank you for reading my answer
- [Django]-Django models: mutual references between two classes and impossibility to use forward declaration in python
- [Django]-How to completely dump the data for Django-CMS
- [Django]-How to make an auto-filled and auto-incrementing field in django admin
2👍
I’m using MySQL.
The solution, for me, was to delete the files inside migrations folder (all but __ init__.py), DROP
and CREATE
database in MySQL Workbench and run python manage.py makemigrations
and python manage.py migrate
again.
Therefore, I had to create a new superuser and all my data was lost 🙁
- [Django]-Django AutoField with primary_key vs default pk
- [Django]-Django 1.3.1 compilemessages. Error: sh: msgfmt: command not found
- [Django]-Django: Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found
0👍
If you are still in development and can take the pain of filling out the db data again then here’s what all you need to know!.
you need to first delete all the files related with db(including sqlite.py if it exists), you can do this by the help of below following ways.
find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
find . -path "*/migrations/*.pyc" -delete
Now either delete the entire data,tables of your DB or just Drop the db and make a new one and do the migrations separately for each app and migrate it.
python manage.py makemigrations appname
python manage.py migrate appname
then if you get any error for the session like "ProgrammingError: relation "django_session" does not exist"
then follow these steps below:
python manage.py migrate --fake sessions zero
then your sessions migrate will be
python manage.py showmigrations
sessions
[ ] 0001_initial
then migrate with --fake-initial
again
python manage.py migrate --fake-initial
now do try to the runserver again and the problem must have been by gone now, if not then please let me know,I’ll try my best possible way to solve it.
Thanks for looking at this.
- [Django]-Django models.py Circular Foreign Key
- [Django]-How to add superuser in Django from fixture
- [Django]-How to add new languages into Django? My language "Uyghur" or "Uighur" is not supported in Django
-1👍
If your migration works locally and not on server do this for server;
root@abcomp:~/var/www/yourapp$sudo -u postgres psql
#list your databases
postgres=#\l
postgres=#\c your_dbname;
your_db=# delete from django_migrations;
# after pulling the latest working changes
(venv)root@abcomp/var/www/yourapp$./manage.py migrate --fake
- [Django]-Cannot access django app through ip address while accessing it through localhost
- [Django]-Malformed Packet: Django admin nested form can't submit, connection was reset
- [Django]-Heroku, postgreSQL, django, comments, tastypie: No operator matches the given name and argument type(s). You might need to add explicit type casts