[Django]-Django.db.utils.NotSupportedError in sqlite why not supported in sqlite

32👍

Go to related migration file(automatically created in migrations directory after makemigrations command) and add atomic = False to the Migration class. Migration(migrations.Migration):. Then you can migrate the changes.

example code:

# Generated by Django 2.1.14 on 2019-12-02 07:07

from django.db import migrations, models


class Migration(migrations.Migration):
    atomic = False # **<<< HERE**

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='ebayLog',
            fields=[

21👍

If you still have the problem here is a example:

# Generated by Django 2.1 on 2018-08-16 21:22

from django.db import migrations


class Migration(migrations.Migration):
    atomic = False # <<<< THIS LINE

    dependencies = [
        ('shop', '0004_product_imgfeat'),
    ]

    operations = [
        migrations.RenameModel(
            old_name='Category',
            new_name='CategoryShop',
        ),
    ]

3👍

I migrated many times after I got this error.

Then I did what Selim said above and I also added atomic = False after class Migration(migrations.Migration): in every migration file, which was a little silly because I didn’t know which file was THE related migration file…

Then I searched the “atomic=False” in Django documentation and I found these:1
2

As the error “Renaming the ‘posts_file’ table while in a transaction is not supported on SQLite” described we know that renaming while in a transaction is not supported on SQLite, so adding atomic=False is needed. But I don’t know about DDL transactions so that’s too much for me…

2👍

If you don’t want to touch anything and you’ve just started your project (well not necessarily), you can just delete the migration files inside the migrations directory and migrate again.

Otherwise, change the atomic variable in the migrations file to False then you can migrate your changes.

1👍

Another way, if atomic=false method didn’t work, is you can delete generated files in the migration folder and start again by make migrations and migrate

0👍

Iam also getting the same error at categories_coupon model.

  1. Go to app which contains categories_coupon model.
  2. Rename the error raising model. (i renamed the ‘coupon’ model to ‘coupons’)
  3. open the migrations folder.
  4. and add ‘atomic=False’ line to all migrations files whose names related to post_file.
  5. then run makemigrations command.
  6. then run migrate command.
  7. then runserver.

For reference look at my models

0003_coupons.py

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    atomic = False     #this is the line i added.
    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('categories', '0002_auto_20211008_1305'),
    ]

    operations = [
        migrations.CreateModel(
            name='Coupons',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('title', models.CharField(blank=True, max_length=200, null=True)),
                ('code', models.CharField(blank=True, max_length=200, null=True)),
                ('description', models.TextField()),
                ('coupon_type', models.IntegerField(choices=[('%', '%'), ('RS', 'RS')])),
                ('discount', models.DecimalField(decimal_places=2, default=0, max_digits=20)),
                ('max_users', models.IntegerField(default=0)),
                ('used_count', models.IntegerField(default=0)),
                ('startd_date', models.DateField()),
                ('end_date', models.DateField()),
                ('icon', models.FileField(upload_to='uploads/banners')),
                ('is_active', models.IntegerField(choices=[(1, 'Active'), (2, 'Inactive'), (3, 'Deleted')])),
                ('created_date', models.DateTimeField(auto_now_add=True)),
                ('users', models.ManyToManyField(to=settings.AUTH_USER_MODEL)),
            ],
        ),
    ]

0004_rename_coupons_coupon.py
-----------------------------------

from django.conf import settings
from django.db import migrations


class Migration(migrations.Migration):

    atomic=False      #here is the line i added.
    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('categories', '0003_coupons'),
    ]

    operations = [
        migrations.RenameModel(
            old_name='Coupons',
            new_name='Coupon',
        ),
    ]

Leave a comment