0

I have something like this:

class A(Model):
    b = OneToOneField('B', related_name='a')

class B(Model):
    pass

But for obvious reasons I think my models would be better structured like this:

class A(Model):
    pass

class B(Model):
    a = OneToOneField('A', related_name='b')

Unfortunately the models are already in production. I'm familiar with makemigrations/migrate and have had a look through the migration files in the migrations directory. I think what I want is to:

  1. create an a field on B, changing related_name='something_else'
  2. have it initialized using the reverse relation something_else
  3. remove the b field on A.

How can I initialize a field in a migration in such a way?

jozxyqk
  • 16,424
  • 12
  • 91
  • 180

0 Answers0