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',
),
]
- [Django]-How to render Django form errors not in a UL?
- [Django]-Django: How can I put an <a> hyperlink in a django validation error from a forms clean() method?
- [Django]-How to expose a property (virtual field) on a Django Model as a field in a TastyPie ModelResource
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…
- [Django]-Check for presence in a list django template
- [Django]-Django returns 'TemplateDoesNotExist' when using Crispy Forms
- [Django]-DatabaseError: value too long for type character varying(100)
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.
- [Django]-Django Admin app or roll my own?
- [Django]-.filter() vs .get() for single object? (Django)
- [Django]-Django: show raw html (from database) as html, not rendered
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
- [Django]-Django: Non-ASCII character
- [Django]-WARNING: Running pip as the 'root' user
- [Django]-Can I use an existing user as Django admin when enabling admin for the first time?
0👍
Iam also getting the same error at categories_coupon model.
- Go to app which contains categories_coupon model.
- Rename the error raising model. (i renamed the ‘coupon’ model to ‘coupons’)
- open the migrations folder.
- and add ‘atomic=False’ line to all migrations files whose names related to post_file.
- then run makemigrations command.
- then run migrate command.
- 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',
),
]
- [Django]-Overriding AppConfig.ready()
- [Django]-How to deal with "SubfieldBase has been deprecated. Use Field.from_db_value instead."
- [Django]-Where is a good place to work on accounts/profile in Django with the Django registration app?