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
Related
i am new to django developement after making changes to my model i tried to run the command python manage.py makemigrations my_app
it detects changes in my model and shows me the message
todoapp/migrations/0001_initial.py
- Create model confess
- Create model UserChoice
- Create model comment
but on executing python manage.py migrate my_appcommand i've got this message
No migrations to apply.
i usually do this after making changes in models, i don't know what happened now.
plss help me.
Firstly, try
python manage.py makemigrations my_app
python manage.py migrate
If this does not work and the project is still in development:
Delete migrations folder and pycache folder.
Delete db.sqlite3 (your database).
Make and apply migrations again.
I think this will work.
Delete all migrations files and __pychache__except__init__.py from your project and app. Also db.sqlite3 database then rerun makemigrations and migrate commands. It should solve your issue.
I am trying to migrate dajngo-background-tasks on my app hosted in heroku. Migrations worked normally locally but when I tried to run:
heroku run python manage.py migrate
It returned 'No migrations to apply'
I've added 'background_task', to INSTALLED_APPS
I ran
heroku run python manage.py makemigrations background_task
And it created the required migrations
I even tried running
heroku run python manage.py migrate background_task
causing "CommandError: App 'background_task' does not have migrations."
PS: One thing I noticed is that when running migrate locally I get this text
Apply all migrations: admin, background_task, auth, contenttypes, sessions, <my_app>
But when I run it on the server I get
Apply all migrations: admin, auth, contenttypes, sessions, <my_app>
Every form of help will be very much appreciated!
You must not run makemigrations via heroku run. You must run it locally, commit the resulting migrations and push them to heroku, then run them there.
This is due to missing migrations in the django-background-tasks package. This issue has been fixed in the latest version. If you install 1.1.9 the deployment to heroku should work.
I have a production web project running with a decent amount of data in the MySQL db. I am trying to update the database with some changes to an app called "enterlink." I've made new elements in the existing models and created new models altogether. Before this migration, I have never touched the schema of the db since originally running syncdb to create it. When I run: "python manage.py makemigrations enterlink" the below output appears(pic). My question is, why is this happening? The DB already includes all the models that it lists in the picture so why is it registering those lists of models? When I go to finish the migration by doing "python manage.py migrate" or "python manage.py migrate --fake enterlink" (pic again), I get an output shown but my database schema remains identical to the old db and any new code generates errors. Can anyone tell me what is likely the problem? I would be really appreciative of any advice. It's been very frustrating since I'm not sure what I'm missing.
What you have done is that you have ran the command python manage.py syncdb before running python manage.py makemigrations myapp and python manage.py migrate myapp. That is why syncdb created the database schema and the migration was faked because schema already exists. I will suggest to use python manage.py makemigrations myapp and python manage.py migrate myapp and not to use syncdb as its deprecated in Django 1.7.
If you change anything in your model, just run makemigrations and migrate command. Syncdb isn't necessary.
This question and relevant answers are intriguing me. Thus I want to share my experience on maintaining live database and migrations.
Tested in django1.5.5
Initializing the database:
./manage.py syncdb --noinput
./manage.py migrate
./manage.py syncdb
Now I have created the database.
Doing a migration for an app:
./manage.py schemamigration myapp --initial
./manage.py migrate myapp --fake
Now do necessary changes in your model
./manage.py schemamigration myapp --auto
./manage.py migrate myapp
Im newbie for schemamigration too, but i will explain how it works for me:
First you create app and then
./manage.py sycndb, so tables are created then you can
./manage.py makemigrations myapp --initial
so now initial migrations are created and you should apply them
./manage.py migrate myapp
now you can change your models : add,change fields, anything you want and then
./manage.py makemigrations myapp --auto
this will create migrations for changes and now you need to apply them
enter code here./manage.py migrate myapp
so this actually will create new tables in db
I have a Django-CMS project running on a Cedar stack using Django 1.7.1 and Python 3 at Heroku.
I can create a migration just fine using: heroku run python manage.py makemigrations which returns:
Migrations for 'zinnia':
0002_entry_content_placeholder.py:
- Add field content_placeholder to entry
However, running the migration via: heroku run python manage.py migrate returns:
Operations to perform:
Synchronize unmigrated apps: mptt, tagging, djangocms_admin_style, localflavor, django_comments, robots, ckeditor, sekizai, compressor, cmsplugin_plaintext, storages
Apply all migrations: admin, cms, zinnia, sessions, contenttypes, sites, auth, djangocms_link, djangocms_file, djangocms_picture, djangocms_text_ckeditor, menus
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
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.
Re-running makemigrations and migrate simply returns the same error statement. What am I doing wrong?
im not so sure on that one, but after you ran the Migration, the file created:
0002_entry_content_placeholder.py
is as you notice, the second migration file.
If its an option for you, you could try to delete/rename the migration folder/files and run makemigrations again.
I got kinda the same error some time ago, and if i remember right, that did the trick.
Sorry for bad english
I'm trying to get South for Django to work on Hereoku. It didn't seem that hard, thanks to this example. However, I'm using a workaround for a bug in south that prevents initiating south when a custom user model is used in Django.
I use the following south commands local to initiate South (work around):
python manage.py syncdb
python manage.py convert_to_south myapp
python manage.py migrate myapp 0001 --fake
After that I pushed the code to Heroku and tried the following steps on Heroku:
python manage.py syncdb // this didn't sync the south apps
python manage.py convert_to_south myapp
// This gave the error saying that the apps were already added to south
My second try (after Heroku db reset and new push):
python manage.py syncdb // this didn't sync the south apps
python manage.py migrate
// Same south error as described in the south bug ticket
Is there anyone who can put me in the right direction?
I've searched for the answer in many places, but the only solution seems to generate the migrations files locally and push them to Heroku. That's something I wish I could prevent, but it is the only working option.
Hopefully, this will be solves as of Django 1.7, when migrations are built into Django. Until then, I moved away from Heroku.