1π
I think you can use django migrations
to do that.
-
Add a
OneToOne
field pointing to the modelUser
, you might need to addrelated_name
for that. -
Create one migration that apply the field to database.
-
Create a data migration and copy the
ForeignKey
value fromuser_account
to the new field for eachDirector
. -
Delete your
user_account
field in model, then create another migration to apply the deletion to the database.
2π
ForeignKey
and OneToOneField
are the same, except OneToOneField
has a unique constraint. Try changing the field in your models and running makemigrations
β I think Django should be smart enough to be able to create the required migration.
Before you start, you need to make sure that there arenβt multiple director instances pointing to the same user, because this isnβt allowed by a one to one field.
- [Django]-How frequently should Python decorators be used?
- [Django]-The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute
- [Django]-Dynamically updating values of a field depending on the choice selected in another field in Django
1π
There is not much difference between ForeignKey
and OneToOneField
. If you run directly change the model field type, your data will not be disturbed. After changing the model field type, run makemigrations
.
- [Django]-Bypassing Django CSRF Protection using external POST Request
- [Django]-Django social-registration redirect url sometimes /social/setup and sometimes /accounts/profile . Why?
- [Django]-Verbose_name_plural unexpected in a model?
- [Django]-Custom django registration form