Open zeloras opened 2 years ago
This is unfortunate. We may need to add an if condition for the driver in our models, but it's hacky. I never found a way to not force the auto field settings migration to allow the default again... thoughts on the best course of action?
I am having this same issue. Is it a problem with mssql or with jwt framework?
same problem
LuisRG30
goes like this. same error with mssql
found not the best way to fix it:
delete all migrations from jwt framework in VENV
Delete string with 'ID' from venv/Lib/site-packages/rest_framework_simplejwt/token_blacklist/models.py
and another one below
then try to migrate
Hahaha, yeah. Actually did that. Working ok.
El dom, 13 nov 2022 a la(s) 12:43, Semyon @.***) escribió:
jwt goes like this. same error with mssql
found not the best way to fix it
delete all migrations from jwt framework in VENV [image: изображение] https://user-images.githubusercontent.com/46165137/201536525-1d54de09-2c1f-43d1-90c0-cba4f934f456.png
Delete string with 'ID' from venv/Lib/site-packages/rest_framework_simplejwt/token_blacklist/models.py [image: изображение] https://user-images.githubusercontent.com/46165137/201536642-aa9a35d0-e46a-4cb0-88c0-6f578d362a67.png
then try to migrate
— Reply to this email directly, view it on GitHub https://github.com/jazzband/djangorestframework-simplejwt/issues/615#issuecomment-1312794940, or unsubscribe https://github.com/notifications/unsubscribe-auth/AN6ZDTCHMPUWBU2WAVMSOBLWIEZFHANCNFSM6AAAAAAQNSYEFA . You are receiving this because you commented.Message ID: @.***>
LuisRG30
goes like this. same error with mssql
found not the best way to fix it:
delete all migrations from jwt framework in VENV
Delete string with 'ID' from venv/Lib/site-packages/rest_framework_simplejwt/token_blacklist/models.py
and another one below
then try to migrate
could you elaborate on what you meant by add another one below? I am facing the same issue! could you message me on discord- r4z33n#9710
LuisRG30
goes like this. same error with mssql
found not the best way to fix it:
delete all migrations from jwt framework in VENV
Delete string with 'ID' from venv/Lib/site-packages/rest_framework_simplejwt/token_blacklist/models.py
and another one below
then try to migrate
could you elaborate on what you meant by add another one below? I am facing the same issue!
could you message me on discord- r4z33n#9710
It means that there are several variables "ID" in
venv/Lib/site-packages/rest_framework_simplejwt/token_blacklist/models.py
and you need to delete them all.
Sorry, have no discord
This is a problem with MSSQL; I was testing only on Postgres and SQLite.
Is this problem only encountered when upgrading between versions or is this a problem for initial migration as welll?
This is a problem with MSSQL; I was testing only on Postgres and SQLite.
Is this problem only encountered when upgrading between versions or is this a problem for initial migration as welll?
It's a problem at initial migration, as django goes through each migration step. At 0001_initial, the two 'id' fields are declared as AutoFields, and later on 0008 tries to alter these to BigAutoFields.
Root cause is MSSQL backend does not support altering AutoField to BigAutoField.
I've played around with the migration files so 0001 declares mentioned fields as BigAutoField (copied field settings from 0010_fix_migrate_to_bigautofield) and removed 0008 and 0010 migration steps. Also replaced dependency in 0011 from 0010 to 0007.
In 0001_initial.py:
In 0011_linearizes_history.py:
Don't forget to remove these from the migrations folder:
Migration went well after these changes. Feels like 1984 though.
The fastest fix for me was to delete all migrations and create them new with py manage.py makemigrations rest_framework_simplejwt afterwards. This gave me one clean 0001_initial.py migration with everything needed.
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name="OutstandingToken",
fields=[
("id", models.BigAutoField(primary_key=True, serialize=False)),
("jti", models.CharField(max_length=255, unique=True)),
("token", models.TextField()),
("created_at", models.DateTimeField(blank=True, null=True)),
("expires_at", models.DateTimeField()),
(
"user",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"ordering": ("user",),
"abstract": False,
},
),
migrations.CreateModel(
name="BlacklistedToken",
fields=[
("id", models.BigAutoField(primary_key=True, serialize=False)),
("blacklisted_at", models.DateTimeField(auto_now_add=True)),
(
"token",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
to="token_blacklist.outstandingtoken",
),
),
],
options={
"abstract": False,
},
),
]
Sadly this is still an issue. I ended up using token auth w/ Djoser. I hope the devs will have a look at this soon. I mean, it doesn't NEED to be set up as AutoField initially, right?
The conflicting migrations forced us to set the pk attribute. If you find a backwards compatible solution, a PR is welcome. Due to time constraints, I don't have the time to support this ticket.
You can fix this by removing the unique index constraint from the token_blacklist_blacklistedtoken table in the database, which will have a name similar to this UQ_token_bl_CB3C9....... Then re-run the migrate and that's it. If you want to recreate the unique index, just run in the database: ALTER TABLE dbo.token_blacklist_blacklistedtoken ADD CONSTRAINT UQ_token_id UNIQUE (id);
Good evening! I found one issue and it's related with migration token_blacklist.0008_migrate_to_bigautofield. It seems like mssql not really supports changing field type from Autofield to BigAutoField https://github.com/microsoft/mssql-django/blob/dev/mssql/schema.py#L299
Could you check it please?