Get rid of this issue easily maintaining the following steps:
pip install django==2.1.5
python manage.py makemigrations
and then python manage.py migrate
python manage.py runserver
DONE!
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)
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
Here is what I did to solve this problem:
Go to the virtual environment and install [email protected]
pip install django==2.1.7
Delete the db.sqlite3
file in your root folder.
db.sqlite3
in your root folder.Re-run migrations:
python3 manage.py makemigrations
python3 manage.py migrate
Now it should be working all right.
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.
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
https://github.com/django/django/pull/10733/commits/c8ffdbe514b55ff5c9a2b8cb8bbdf2d3978c188f#diff-0c8f495bfee773ab7b5409533bd6d7ef
for me, it was from my django version (that was 2.1) install higher version (I used 2.1.5 for some reasons) ** delete db.sqlite3, and everything in migration folder except init.py run command:
pip install django==2.1.5 --upgrade
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With