54π
I just came across this myself, it looks to be related to https://code.djangoproject.com/ticket/29182. For now, you can just downgrade your version of sqlite to a version prior to 2.6 (e.g. 2.5.1)
86π
Get rid of this issue easily maintaining the following steps:
- keep django version 2.1.5 (the issue addressed in this version)
pip install django==2.1.5
- Delete the SQLite db
- Migrate again
python manage.py makemigrations
and thenpython manage.py migrate
- Start the server
python manage.py runserver
DONE!
- [Django]-Tying in to Django Admin's Model History
- [Django]-How do I POST with jQuery/Ajax in Django?
- [Django]-How to update fields in a model without creating a new record in django?
20π
Just did this and it resolved the problem:
pip install Django --upgrade
Then:
python manage.py migrate
python manage.py makemigrations app
python manage.py migrate
- [Django]-How to change field name in Django REST Framework
- [Django]-How do I make many-to-many field optional in Django?
- [Django]-Feedback on using Google App Engine?
14π
Here is what I did to solve this problem:
-
Go to the virtual environment and install
django@2.1.7
pip install django==2.1.7
-
Delete the
db.sqlite3
file in your root folder. - Create the new
db.sqlite3
in your root folder. -
Re-run migrations:
python3 manage.py makemigrations python3 manage.py migrate
Now it should be working all right.
- [Django]-Proper way to handle multiple forms on one page in Django
- [Django]-How to deal with "SubfieldBase has been deprecated. Use Field.from_db_value instead."
- [Django]-How do Django models work?
13π
The problem is caused by the modified behaviour of the ALTER TABLE RENAME
statement in SQLite 3.26.0 (see compatiblity note). They also introduced the PRAGMA legacy_alter_table = ON
statement in order to maintain the compatibility with previous versions. The upcoming Django release 2.1.5 utilizes the previously mentioned statement as a hotfix. Itβs expected on January 1, 2019.
- [Django]-How to access request body when using Django Rest Framework and avoid getting RawPostDataException
- [Django]-Django admin ManyToMany inline "has no ForeignKey to" error
- [Django]-Error when using django.template
10π
go to this folder django/db/backends/sqlite3
backup schema.py
file to another folder
open the original schema.py in a text editor
there you can see a code snippet like
def __enter__(self):
# Some SQLite schema alterations need foreign key constraints to be
# disabled. Enforce it here for the duration of the schema edition.
if not self.connection.disable_constraint_checking():
raise NotSupportedError(
'SQLite schema editor cannot be used while foreign key '
'constraint checks are enabled. Make sure to disable them '
'before entering a transaction.atomic() context because '
'SQLite3 does not support disabling them in the middle of '
'a multi-statement transaction.'
)
self.connection.cursor().execute('PRAGMA legacy_alter_table = ON')
return super().__enter__()
comment them and paste the following code snippet
def __enter__(self):
# Some SQLite schema alterations need foreign key constraints to be
# disabled. Enforce it here for the duration of the transaction.
self.connection.disable_constraint_checking()
self.connection.cursor().execute('PRAGMA legacy_alter_table = ON')
return super().__enter__()
This worked for me. (the backup for the schema.py is in case the work go wrong ; D
)
for more info
- [Django]-Getting TypeError: __init__() missing 1 required positional argument: 'on_delete' when trying to add parent table after child table with entries
- [Django]-How do I perform HTML decoding/encoding using Python/Django?
- [Django]-Auto-create primary key used when not defining a primary key type warning in Django
7π
-
First, stop the server and delete db.sqlite3.
-
Then, you need to run:
python manage.py makemigrations
python manage.py migrate
-
After running this command you need to create super user. To Create
Super User, run:
python manage.py createsuperuser
Enter the super user details there. -
Run your server again.
There you go.
- [Django]-Chained method calls indentation style in Python
- [Django]-Images from ImageField in Django don't load in template
- [Django]-What does "'tests' module incorrectly imported" mean?
6π
I solved the problem by upgrading Django from 2.1.4 to 2.1.5 by running
pip install --upgrade django==2.1.5
but I had to rebuild the project anew, because the bug seems to be somehow related to the objects I inserted into the database by using the old version of Django.
UPDATE:
Instead of deleting the entire project, it was sufficient to delete only the database. And then to run
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
- [Django]-How can I handle Exceptions raised by dango-social-auth?
- [Django]-How to create an object for a Django model with a many to many field?
- [Django]-Django: How can I create a multiple select form?
6π
In my case, it was because of my django version (that was 2.1)
-
Install higher version (2.1.5+ or higher)
-
Delete
db.sqlite3
, and everything in migration folder except__init__.py
-
Run these commands:
pip install django==2.1.5 --upgrade
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
- [Django]-How to write setup.py to include a Git repository as a dependency
- [Django]-Determine variable type within django template
- [Django]-DatabaseError: current transaction is aborted, commands ignored until end of transaction block?
5π
Even after upgrading to the latest Django 2.2.12 and running either migrate
or the official database rebuild script, I got the same error with __old_
:
django.db.utils.IntegrityError: The row in table 'djangocms_blog_post_translation' with primary key '2' has an invalid foreign key: djangocms_blog_post_translation.master_id contains a value '2' that does not have a corresponding value in djangocms_blog_post__old.id.
Hereβs my hack:
- dump the database contents to sql:
sqlite3 my_db.db .dump > my_db.sql
- run a regex over the sql output, replacing
__old" ("id")
with" ("id") DEFERRABLE INITIALLY DEFERRED
- delete the old database file
- load the modified sql into a new database:
sqlite3 my_db.db < my_db.sql
- ??? & profit
- [Django]-ImportError: cannot import name 'β¦' from partially initialized module 'β¦' (most likely due to a circular import)
- [Django]-Pulling data to the template from an external database with django
- [Django]-Pass request context to serializer from Viewset in Django Rest Framework
4π
Same thing is happened to me, very frustrating. I use anaconda for my environments, I found that I couldnβt remove sqlite without immediately reinstalling the most up to date version of sqlite. Trying an older version of django also didnβt seem to work. The only solution that has worked for me is by using a PostgreSQL database. Itβs certainly not ideal but I am planning on utilising the PostgreSQL database in the future so this wasnβt a complete waste of time. If you find yourself in the same place as I was then this video may be helpful if you want to know how to connect the PostgreSQL database with your django project.
Youβll need to install the postgreSQL database before actually making the changes in settings.py, the installation is more of less clicking Next on all the options. However, remember the username and password you use during installation.
- [Django]-Django get a QuerySet from array of id's in specific order
- [Django]-Can't connect to local MySQL server through socket '/tmp/mysql.sock
- [Django]-Using a UUID as a primary key in Django models (generic relations impact)
4π
keep django version 2.1.5
This issue is adressed only in this version of Django
- pip install django==2.1.5
- Delete the SQLite db
- Run migration
- Start the server python manage.py runserver
This solves the above issue
- [Django]-Set Django IntegerField by choices=β¦ name
- [Django]-Uwsgi installation error in windows 7
- [Django]-Django filter on the basis of text length
2π
Open => /YourAppFolder/migrations/ You would to see the migrating files just like β0001_initial.pyβ delete all of these files. And run the follwing command
1- python manage.py makemigrations
2- python manage.py migrate
Hope, it must solve your problem
- [Django]-Python (and Django) best import practices
- [Django]-Django Rest Framework with ChoiceField
- [Django]-How to run celery as a daemon in production?
2π
For others who donβt want to downgrade any software, you can head into your settings.py
file and in the DATABASES
dict, you can replace .sqlit3
with .postgresql
, and right underneath it change the db.sqlit3
to db.sql
. This switches your default db to using postgreSQL.
In doing so, youβll need to pip install psycopg2
.
Delete your db.sqlite3
file (if you have one/donβt care about losing whatβs in it) and everything else that isnβt the __init__.py
file in your appβs migration folder. Once youβve done all of that, you can run python manage.py makemigrations
and python manage.py migrate
and then it should work π
Hope I was able to help someone!
- [Django]-Django REST Framework custom fields validation
- [Django]-Getting TypeError: __init__() missing 1 required positional argument: 'on_delete' when trying to add parent table after child table with entries
- [Django]-How to use "get_or_create()" in Django?
2π
For the above problem and solution is:
1) Go to the terminal and type in pip install django==2.1.7
or the latest version of django
2) After the installation,In the terminal type in python manage.py makemigrations
,and then python manage.py migrate
3) In the terminal,Start the server with code python manage.py runserver
4) Login to the admin server with the password and the add the product,It will successfully add the product.
- [Django]-Many-To-Many Fields View on Django Admin
- [Django]-Django-allauth: Linking multiple social accounts to a single user
- [Django]-What is the difference between cached_property in Django vs. Python's functools?
1π
I had the same issue except that I had 2 sqlite databases and custom database router. I managed to get it working by downgrading Django to 1.11.20 and no need to recreate the databases.
- [Django]-Homepage login form Django
- [Django]-How do I reference a Django settings variable in my models.py?
- [Django]-Django's Double Underscore
1π
you need to upgrade Django, this issue has been fixed in this PR https://github.com/django/django/pull/10733
- [Django]-How to show a many-to-many field with "list_display" in Django Admin?
- [Django]-Django admin make a field read-only when modifying obj but required when adding new obj
- [Django]-How to combine multiple QuerySets in Django?
1π
First, update django version:
pip install django --upgrade
then
./manage.py makemigration
./manage.py migrate
./manage.py runserver
- [Django]-Django/DRF β 405 Method not allowed on DELETE operation
- [Django]-How to delete project in django
- [Django]-How can I keep test data after Django tests complete?
0π
Steps:
-
Uninstall current Django from your ENV. Just delete the folder "anaconda3/envs/yourenv/lib/python3.7/site-packages/Django all versions..
Note: Only for Anaconda users, other users should figure out how to uninstall a package from your ENV.
-
Download the repo as zip file.
-
Extract zip.
-
Switch to your ENV.
-
Enter the extracted folder.
-
Run
"python setup.py install"
And install Django. -
Delete your previous
db.sqlite3
file. Now apply the migrations again to create a newdb.sqlite3
file.Note: I donβt know how to fix previous dbfile and prevent data loss. So please tell me if you know.
-
Run Server.
Congrats! It works fine now.
Update to latest django in January from the official Django release.
- [Django]-How to expire session due to inactivity in Django?
- [Django]-How to get username from Django Rest Framework JWT token
- [Django]-What's the difference between CharField and TextField in Django?
0π
There are just 4 things I did on command line and it fixed mine.
- ctrl + c (stop server)
py manage.py makemigrations
py manage.py migrate
py manage.py runserver
(start server)
- [Django]-ImportError: No module named 'django.core.urlresolvers'
- [Django]-How does Django's nested Meta class work?
- [Django]-Create custom buttons in admin change_form in Django
0π
For those who cannot resolve this error with above answers, if you had made your app with its name βmainβ, this error may occur cause of same app name issue. So try to change your app name βmainβ to another.
- [Django]-Profiling Django
- [Django]-Python 3 list(dictionary.keys()) raises error. What am I doing wrong?
- [Django]-Running Django with FastCGI or with mod_python
0π
I solved the problem by changing some of my models. I had one named project and one named projects. The database tables got confused and threw me this error.
- [Django]-Retrieving parameters from a URL
- [Django]-How can I chain Django's "in" and "iexact" queryset field lookups?
- [Django]-Django: multiple models in one template using forms
0π
I have solved this issue using below :
1) Delete the db.sqlit3
2) appβs directory delete everything in
pycache
3) manage.py makemigrations, manage.py migrate, manage.py createsuperuser and then manage.py runserver.
- [Django]-Remove pk field from django serialized objects
- [Django]-Django admin: How to display the field marked as "editable=False" in the model?
- [Django]-How to run celery as a daemon in production?
0π
I had the same issue and fixed it by doing the below:
1) Get the latest django
version
2) get the latest SQL Lite
version
3) delete db.sqlite3
file from your project
4) Make a small change to the models.py
(e.g. change the size of a field)
5) generate a new db.sqllite3
file by running the makemigrations
& migrate commands
6) import the newly created db.sqllite3
file into SQL Lite
- [Django]-Django auto_now and auto_now_add
- [Django]-Django: Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found
- [Django]-Django Generic Views using decorator login_required
0π
I installed/downgraded django to 2.2 version ,this removed django 3.x
pip install django==2.2
and then I deleted db.sqlite file and then
I tried
python manage.py makemigrations,
python manage.py migrate
python manage.py creatingsuperuser.
- [Django]-Django storages aws s3 delete file from model record
- [Django]-Django form fails validation on a unique field
- [Django]-How to recursively query in django efficiently?
0π
-
Upgrade Django
pip install Django --upgrade
-
Delete the
db.sqlite3
file the root folder of your project. -
Create the new db.sqlite3 in your root folder by re-running migrations.
python3 manage.py makemigrations
-
Migrate
python3 manage.py migrate
It may work with just this or you may need to create a new superuser if it was deleted.
- Check for your superuser using
python manage.py shell
from django.contrib.auth.models import User
User.objects.filter(is_superuser=True)
If <QuerySet []>
appears there is no user.
Else check if your user exists.
- If your user does not exist create one using
python manage.py createsuperuser
- [Django]-Gunicorn autoreload on source change
- [Django]-Manager isn't available; User has been swapped for 'pet.Person'
- [Django]-Having Django serve downloadable files
-1π
Please check if you havenβt deleted the migration folder from your app
if deleted try to restore the folder and remove migration files or
if deleted permanently create app and copy paste your work and
then
1. Delete db.sqlite3
2. python manage.py makemigrations
3. python manage.py migrate
4. python manage.py createsuperuser
HTH π
- [Django]-How to add superuser in Django from fixture
- [Django]-How can I upgrade specific packages using pip and a requirements file?
- [Django]-Filtering using viewsets in django rest framework
-1π
- Delete db.sqlite3
- makemigrations & migrate
- Create new super user
This works for me
- [Django]-Django β How to set default value for DecimalField in django 1.3?
- [Django]-How to save pillow image object to Django ImageField?
- [Django]-How to filter objects for count annotation in Django?
-1π
Note: Do not follow this trick if you have some personal data in Sqlite3 DB as youβre going to delete Sqlite3 DB
I know many answers are given to this question but only this trick help me to solve this issue as Iβm beginner at python and learning Django.
- Stopped the django webserver running, Ctrl-C
- Delete the db.sqlite3
- Uninstalled Django old verison
- Install latest version of Django with βpip install djangoβ
- Delete all migrations from all apps of your project
Now run these commands in terminal
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
( provide super-user credentials )python manage.py runserver
Now finally login to admin panel with updated super-userβs credentials and try to add record.
Same suggestions at this link by someone
- [Django]-How to use Python type hints with Django QuerySet?
- [Django]-No handlers could be found for logger
- [Django]-Django staticfiles not found on Heroku (with whitenoise)
-2π
django-2.2.7
This worked for me β
1) Delete db.sqlite3.
2) Within each app, within the migrations folder, delete everything other than __init__.py .
3) Within each app,delete __pycache__ folder.
I am not sure if you had to do it for all apps or just the concerned app, but this worked for me.
- [Django]-How can I get tox and poetry to work together to support testing multiple versions of a Python dependency?
- [Django]-How to get superuser details in Django?
- [Django]-Django admin: How to display the field marked as "editable=False" in the model?