99👍
I fix this by running auth first, then the rest of my migrations:
python manage.py migrate auth
python manage.py migrate
19👍
On my environment, I fix this running makemigrations
on all apps that have relationship with django.contrib.auth.models
:
manage.py makemigrations app_with_user_relation manage.py migrate
- [Django]-Django equivalent of SQL not in
- [Django]-How do I force Django to ignore any caches and reload data?
- [Django]-How to duplicate virtualenv
8👍
If you are using heroku like I was run
heroku run python manage.py makemigrations
This will likely give you a message saying there are now changes. Ignore that then run
heroku run python manage.py migrate
this will give you some output suggesting something has been done.
Finally run
heroku run python manage.py createsuperuser
- [Django]-Django 1.7 – App 'your_app_name' does not have migrations
- [Django]-Proper way to handle multiple forms on one page in Django
- [Django]-How to send html email with django with dynamic content in it?
8👍
This problem is contained by running “makemigrations” for all apps, that have not yet been migrated, i.e. apps that do not yet have an “initial_0001.py” file in their migrations directory.
This is done (in our case we use a makefile) by running for each of these apps:
manage.py makemigrations app_name
Once that is done, you can execute:
manage.py migrate
as usual.
The underlying cause for this is that for some reason
manage.py makemigrations
does not always create these initial migrations if they are not already there. And that leads to the mentioned error.
On the contrary,
manage.py makemigrations app_name
does always create them (if not already there). Unfortunately I cannot fathom the reasons for this asymmetry.
- [Django]-Embedding JSON objects in script tags
- [Django]-How do I prevent fixtures from conflicting with django post_save signal code?
- [Django]-Django: manage.py does not print stack trace for errors
4👍
To fix this problem here is what I did:
1) Find all foreign key relation fields like OneToOneField, ForeignKey and ManyToManyFields in your project, including any reusable apps that are referring to auth.User
or import User and set it to settings.AUTH_USER_MODEL as above. At minimum use:
'auth.User'
2) For all the models that have the above, make sure the models have a valid django migration (not south). If they have south migrations, rename the directory to migrations_south and then run the makemigrations command for that app:
./manage.py makemigrations affected_app
Sometimes there is a django migrations folder under a different name, not the default migrations
directory. In such cases, reference this via MIGRATION_MODULES
in your settings.py:
MIGRATION_MODULES = {'filer': 'filer.migrations_django'}
Since the issue was hard to find on larger projects, I commented out all custom apps in INSTALLED_APPS
in settings.py and ran the test command, since it will run migrate and try to re-create the database for you:
./manage.py test
Looks like that fixed it for me. I’m not sure if step 1 is mandatory or just best practice. But you definitely need to convert the apps to migrations.
Cheers!
PS. Be ready for what’s coming in Django 1.9. The syncdb command will be removed. The legacy method of syncing apps without migrations is removed, and migrations are compulsory for all apps.
- [Django]-Automatic creation date for Django model form objects
- [Django]-How to expire session due to inactivity in Django?
- [Django]-Difference between reverse() and reverse_lazy() in Django
0👍
Try referring to the User using this
from django.conf import settings
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='%(app_label)s_%(class)s_user', blank=True, null=True, editable=False)
- [Django]-PIL /JPEG Library: "decoder jpeg not available"
- [Django]-Access request in django custom template tags
- [Django]-Django, template context processors
0👍
I’ve migrated an old Django 1.6 project to Django 1.8 and previously we’ve used syncdb to migrate the database and we did not have initial migration steps for all apps in our project. With Django 1.8, you’ll need a working database migrations. Running
manage.py makemigrations <app_name>
for all apps in our project fixed our problems.
- [Django]-Django Rest framework, how to include '__all__' fields and a related field in ModelSerializer ?
- [Django]-Django.db.utils.OperationalError Could not connect to server
- [Django]-Chained method calls indentation style in Python
0👍
Maybe you have found the answer and resolved the problem, but I wanted to point out that, in my case, the above problem was solved by dropping the database and re-creating it again, with the full privileges of the users. I was able to do this because I’m working on a non-production environment, but doing this on a staging environment is not a good idea, so be careful.
Im using python 2.7.12
and following are the specifications of my virtualenv:
Django==1.10.5
django-crispy-forms==1.6.1
django-registration-redux==1.4
djangorestframework==3.5.3
olefile==0.44
packaging==16.8
Pillow==4.0.0
psycopg2==2.6.2
- [Django]-How to get an ImageField URL within a template?
- [Django]-The QuerySet value for an exact lookup must be limited to one result using slicing. Filter error
- [Django]-Django – Website Home Page