I have two models A, B, they contain a lot of data(int database). Suddenly I decided to add a foreign key in model B to A. But Django can't migrate it because existing rows in table B haven't value for this FK. What should I do in such a situation?
CodePudding user response:
in foreignkey attribute add default=None
CodePudding user response:
from django.db import models
class ModelB(models.Model):
column_one = models.ForeignKey(ModelA, on_delete=models.CASCADE, default = None)