0

I was creating custom user in django for that i wrote following code in initial migration file but when we hit migrate command it gives TransactionManagementError

0001_initial.py

from django.db import migrations
from api.user.models import CustomUser

class Migration(migrations.Migration):
def seed_data(apps,schema_editor):
    user = CustomUser(name = "abc",email = "abc@gmail.com",is_staff = True,is_superuser = True,
                       phone = "9874561230",gender = "Male")
    user.set_password("12345")
    user.save()

dependencies = [

]

operations = [
    migrations.RunPython(seed_data),
]

error occcured:

django.db.transaction.TransactionManagementError: An error occurred in the current transaction. You 
can't execute queries until the end of the 'atomic' block.
Pawan Khande
  • 1
  • 1
  • 1
  • Does this answer your question? [Can't execute queries until end of atomic block in my data migration on django 1.7](https://stackoverflow.com/questions/32205220/cant-execute-queries-until-end-of-atomic-block-in-my-data-migration-on-django-1) – Imran Ali Khan Jan 12 '23 at 06:54

1 Answers1

2

This question will be repeated. Please try this reference.

Reference: Can't execute queries until end of atomic block in my data migration on django 1.7

Riyas Ac
  • 1,553
  • 1
  • 9
  • 23