我写了一个自定义的django migrations命令,如下所示
User = get_user_model()
def populate_asset_assignee(apps, schema_editor):
for user in User.objects.all():
user.save()
# Some more code
用户模型如下
class User(AbstractUser):
username = None
email = models.EmailField(max_length=50, unique=True)
cohort = models.IntegerField(blank=True, null=True)
slack_handle = models.CharField(max_length=50,
blank=True, null=True)
picture = models.CharField(max_length=255, blank=True, null=True)
phone_number = models.CharField(max_length=50, blank=True, null=True)
last_modified = models.DateTimeField(auto_now=True, editable=False)
password = models.CharField(max_length=128, blank=True, null=True)
location = models.ForeignKey('SomeCentre',
blank=False,
null=True,
on_delete=models.PROTECT)
# Some more fields
我最近添加了location字段,并为其应用了自定义迁移后应用的迁移。我遇到的问题是,每当我尝试在测试数据库或新数据库上进行迁移时,都会收到django.db.utils.ProgrammingError: column core_user.location_id does not exist
内出现的错误populate_asset_assignee
。我尝试做user in User.objects.all()
时的方法
为什么要检查location_id
的任何想法,但我尚未对位置字段应用迁移。