26👍
I had this problem and I had to comment out everything in urls.py
that referenced views.py
, then run makemigrations
.
15👍
Make sure that you don’t have any class variables in your code that are calling Django manager
For example:
class SomeViewSet(viewsets.ViewSet):
se = SomeEntity.objects.first() # fetching some entity on the class level
def list(self, request):
# the rest of the code
So, when you try to create/apply migrations, this variable will also try to initialise, and will try to access SomeEntity
, but at that moment that entity doesn’t even exist, and the error occurs.
- 'WSGIRequest' object has no attribute 'session' while upgrading from django 1.3 to 1.9
- Django template {%for%} tag add li every 4th element
- Does changing a django models related_name attribute require a south migration?
- Django HTML E-mail template doesn't load css in the e-mail
3👍
Try to migrate particular app using following process. Refer Django migrations
python manage.py makemigrations
Initial migration created then run migrate command with app name
python manage.py migrate appname1, appname2
- Django, Security and Settings
- How to emit SocketIO event on the serverside
- How to dynamically add EC2 ip addresses to Django ALLOWED_HOSTS
3👍
If all other solutions mentioned fail, if you are still in development probably the easiest solution is dropping the database (in pgAdmin 4 2.0, right-click on database) and then run makemigrations
and migrate
.
- How show personalized error with get_object_or_404
- Django admin – select reverse foreign key relationships (not create, I want to add available)
2👍
When you run a query before applying migrations this error appears.
If you got this error during python manage.py makemigrations
or python manage.py migrate
you must consider that makemigrations
and migrate
commands run after successful django bootstrap! So this error happens when you run a query during django bootstrap! So you must find the place you run this query during bootstrap progress.
For example, during bootstrap, django reads root {project}/urls.py
and its nested imports. If you use views or viewsets in urls.py and they are run a query during initializing (in their __init__
method or __init__.py
file or somewhere etc.), it happens!
In this situation and similars, you must comment out any entry in urls.py and similar files which cause running a query during bootstrap and prevent them from running by raising of exception during bootstrap! makemigrations
and migrate
need successful bootstrap to be run!
If your commented out code needs to makemigrations
and migrate
handcooks :D, it needs to be patient and be silent for a cycle or a while ;), and after a successful migrations it could be active and verbose ;D.
- How to test a Django on_commit hook without clearing the database?
- Django Rest Framework debug post and put requests
- Django template tag: How to send next_page in {url auth_logout}?
- Django Testing – Hard code URLs or Not
1👍
Your app is trying to call some DB entries that does not exist.
If you are trying to migrate it to a new database, one of your options is to export a dump of old database and import it to your new DB.
For example in PostgreSQL, import the database using below command then migration will work!
sudo -u postgres -i psql mydb < mydb-export.sql
- When to use NullBooleanField in Django
- Python/Django development, windows or linux?
- AttributeError: 'NoneType' object has no attribute 'attname' (Django)
1👍
Django is running an optional check. Pass the --skip-checks
flag in your call to manage.py
.
- How can I best find out how django works internally?
- Indirect inline in Django admin
- Django OneToOneField with possible blank field
- Django, REST and Angular Routes
0👍
If you’re running in local,
For each Django app (maybe you have only one), erase the content of the migrations
folder.
Then, run python manage.py makemigrations app1 app2 app3
(if you have 3 Django apps named app1, app2, app3). This will (re)create the migrations files required to migrate your database
Then, run python manage.py migrate
. It will apply the migration files you just created.
0👍
This error may be related to previous database error. So if you created a new database and you also face that type of error, you can simply run the command with the app name:
python manage.py makemigrations <"app name">
python manage.py migrate <"app name">
0👍
First remove all urls from urls.py.
Create simple function view for viewing nothing:
def simple(request):
context = {}
return render(request, 'base.html', context)
and add urls to urls.py
do migrate:
python manage.py migrate
after migrate, recover the deleted urls.py contents
- Django logging – django.request logger and extra context
- Registering Django system checks in AppConfig's ready() method
- Django's get_current_language always returns "en"
0👍
For me the error came from some initialization code I put into the app.ready() method. Commenting that part of code allowed me to run the command makemigrations without any issue.
I believe app.ready is called at some point by manage.py even for the makemigrations command, which caused my code to query my database before any migration.
I found the problematic code thanks to the traceback.
- TypeError: create_superuser() missing 1 required positional argument: 'profile_picture'
- Django-Rest-Framework serializer class meta