-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error with sites migration when using sqlite backend #3587
Comments
The original issue we were trying to address is #3507. The SQL in that migration isn't database agnostic, it's specific to PostgreSQL. This bug was also mentioned on Stackoverflow, where the project was generated from a MySQL fork... Maybe we could skip this piece of code if the DB backend isn't PostgreSQL, although I'm tempted to say that we only maintain PostgreSQL, and hence using another backend is out of scope here. |
A recent change in cookiecutter-django broke migrations for sqlite backends. This can be fixed by using an old version of the migration. See issue: cookiecutter/cookiecutter-django#3587
Assuming the question was answered, this will be automatically closed now. |
@amstilp used the following which so far seems to work; max_id = site_model.objects.order_by('-id').first().id
with connection.cursor() as cursor:
if connection.vendor == "postgresql":
cursor.execute("SELECT last_value from django_site_id_seq")
(current_id,) = cursor.fetchone()
if current_id <= max_id:
cursor.execute(
"alter sequence django_site_id_seq restart with %s",
[max_id + 1],
)
elif connection.vendor == "mysql":
cursor.execute("SELECT MAX(id) FROM django_site")
(current_id,) = cursor.fetchone()
if current_id <= max_id:
cursor.execute(
"ALTER TABLE django_site AUTO_INCREMENT=%s",
[max_id + 1],
) |
I know that sqlite is not officially supported, so this issue is primarily an FYI for anyone else using the
django.db.backends.sqlite3
sqlite backend in initial development. Thesites.0003_set_site_domain_and_name
migration was updated in a recent commit (b58f0e7). After this change, when trying to runpython manage.py migrate
to create the database, I get the following error:I was able to fix this by using the previous version of the
sites.0003_set_site_domain_and_name
migration file.The text was updated successfully, but these errors were encountered: