In my project I am using django 1.8 and for a fresh project if I run
python manage.py runserver
it shows the following message:
You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.
Then if i run the command
python manage.py migrate
it works fine for sqlite.
But if i connect with postgresql in my local_settings.py and run the above migration command then it gives the following error:
django.db.utils.ProgrammingError: relation "django_content_type" does not exist
You probably have an app that has a (generic) foreign key to ContentType. This causes migrations to fail because the database tries to create a foreign key to a table that doesn't exist yet. Try migrating contenttypes first with python manage.py migrate contenttypes and then applying your other migrations.
Related
I have a django project source code, which includes several apps. The source code have been run successfully on one environment, but when transplanted to another device, with the same postgresql version(9.4.4), python version(2.7.5), and django version(1.8.5), but the runserver reports errors like this. The database has been imported in advance.
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "django_migrations" already exists
Try this python manage.py migrate --fake
You can read more about it in official documentation
Try troubleshooting Initial migrations using --fake-initial
python manage.py migrate --fake-initial
https://docs.djangoproject.com/en/1.8/ref/django-admin/#django-admin-option---fake-initial
If you have an empty database you can clear all your migrations and then again run migrations and migrate command.
python manage.py makemigrations
python manage.py migrate
I've been using Django for several months now without any issue but when I went to create a new project and add the super-user, I get the following error:
django.db.utils.IntegrityError: NOT NULL constraint failed: auth_user.last_login
All migrations have been created and applied successfully. I have destroyed and recreated the database a half dozen times to no avail. App migrations run without any problem whatsoever and this is the first time I've encountered this issue in an Django project.
I just realized this message was buried in the dozens of lines of error messages:
You have 12 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
Running just manage.py migrate and/or manage.py migrate appname did not apply the required system migrations. I had to do each one individually this time for some reason.
After running each one individually I was able to create a superuser without a problem:
manage.py migrate admin
manage.py migrate auth
manage.py migrate contenttypes
manage.py migrate sessions
I've never had to do that before, however. If anyone knows a reason as to why that happened I'd love to know but I've solved the main issue for now.
I'm too used
manage.py migrate admin
manage.py migrate auth
manage.py migrate contenttypes
manage.py migrate sessions
this helped for me
python manage.py createsuperuser
I've dropped my Postgres database by accident. Then as per this solution I deleted the migration files but now can't execute the third step's command "python manage.py migrate --fake".
RuntimeError: Error creating new content types.
Please make sure contenttypes is migrated before trying to migrate apps individually.
psycopg2.ProgrammingError: relation "django_content_type" does not exist
LINE 1: ..."."app_label", "django_content_type"."model" FROM "django_co...
^
I tried running "python manage.py migrate contenttypes" and "python manage.py makemigrations contenttypes --empty" but neither work.
Using django 1.9.5
Synchronise your project first:
like this:
python manage.py syncdb
when finish you can run: python manage.py makemigrations and last python manage.py migrate
I've dropped all tables from my postgres db. Now, while running
python manage.py syncdb
I'm getting error that abc fields doesn't exist in xyz table.
It's probably some sort of django cache issue. Error is of this format:
django.db.utils.ProgrammingError: relation "mmb_data_genre" does not exist
LINE 1: ...b_data_genre"."id", "mmb_data_genre"."genre" FROM "mmb_data_...
Any suggestions how to fix this?
Note - I'm using django 1.8.2 and
python manage.py makemigratons
or
python manage.py runserver
is throwing same error.
syncdb in django 1.8 is merely an alias for the migrate command but with the additional step of creating a superuser.
Deprecated since version 1.7: This command has been deprecated in
favor of the migrate command, which performs both the old behavior as
well as executing migrations.
But syncdb (migrate) should be executed only after you have done makemigrations [app_label] but in your case you seem to have the order in reverse.
Try
./manage.py makemigrations
./manage.py migrate
I trying to revert the migrations of my Django application. I have five migrations which are synced with the database. I use the following command:
$ python manage.py migrate zero
This fails with the following error message:
CommandError: App 'zero' does not have migrations (you cannot selectively sync unmigrated apps)
You should provide the app label to migrate:
python manage.py migrate myapp zero