I'm trying to modify a M2M field to a ForeignKey field. The command validate shows me no issues and when I run syncdb :
ValueError: Cannot alter field xxx into yyy they are not compatible types (you cannot alter to or from M2M fields, or add or remove through= on M2M fields)
So I can't make the migration.
class InstituteStaff(Person):
user = models.OneToOneField(User, blank=True, null=True)
investigation_area = models.ManyToManyField(InvestigationArea, blank=True,)
investigation_group = models.ManyToManyField(InvestigationGroup, blank=True)
council_group = models.ForeignKey(CouncilGroup, null=True, blank=True)
#profiles = models.ManyToManyField(Profiles, null = True, blank = True)
profiles = models.ForeignKey(Profiles, null = True, blank = True)
Any suggestions?
Potential workarounds:
Create a new field with the ForeignKey relationship called
profiles1
and DO NOT modifyprofiles
. Make and run the migration. You might need arelated_name
parameter to prevent conflicts. Do a subsequent migration that drops the original field. Then do another migration that renamesprofiles1
back toprofiles
. Obviously, you won't have data in the new ForeignKey field.Write a custom migration: https://docs.djangoproject.com/en/1.7/ref/migration-operations/
You might want to use
makemigration
andmigration
rather thansyncdb
.Does your
InstituteStaff
have data that you want to retain?