I used to have a model like this:
class Car(models.Model):
manufacturer_id = models.IntegerField()
There is another model Manufacturer that the id field refers to. However, I realized that it would be useful to use django's built-in foreign key functionality, so I changed the model to this:
class Car(models.Model):
manufacturer = models.ForeignKey(Manufacturer)
This actually works fine immediately, queries work without errors, everything is great, except that if I try to run migrations, Django outputs the following:
- Remove field manufacturer_id from car
- Add field manufacturer to car
Doing this migration would clear all the existing relationships in the database, so I don't want to do that. I don't really want any migrations at all, since queries like Car.objects.get(manufacturer__name="Toyota") work fine. I would like a proper database foreign key constraint, but it's not a high priority.
So my question is this: Is there a way to make a migration or something else that allows me to convert a existing field to a foreign key? I can't use --fake since I need to reliably work across dev, prod, and my coworkers computers.