I currently added this model to my app
from mainApp.models import modelPatient
class modelBodyParts(models.Model):
part_name = models.CharField(max_length=1000, unique=False , default="")
modelPatient = models.ForeignKey(modelPatient)
result = models.CharField(max_length=3000, unique=False , default="")
Now the makemigrations and migrate commands give me the following error
>>python manage.py makemigrations
>>python ./manage.py migrate
ValueError: The field interviewApp.modelInterviewAnswers.patients was declared with a lazy reference to 'mainApp.modelpatients', but app 'mainApp' doesn't provide model 'modelpatients'
I am not sure what that means. But I do remember that at one point mainApp.modelpatients
existed and then it was changed to mainApp.modelpatient
which still exists.How do I resolve this issue and why is this showing up ? Any help would be appreciated.
you can either: temporarily remove your migration, execute python manage.py migrate, add again your migration and re-execute python manage.py migrate. Use this case if the migrations refer to different models and you want different migration files for each one of them.
migrate , which is responsible for applying and unapplying migrations. makemigrations , which is responsible for creating new migrations based on the changes you have made to your models.
To deal with such cases, Django provides a way called fake migration, which applies the migration but does not affect the database schema. In simpler words, for each migration which is faked, an entry is created in django_migrations table but no changes are done in the database schema.
Deleting Django migrations is generally a bad idea. Django keeps track of what's in your db through these migration files, as well as through a table it creates in your db, and if you delete any of this Django will start throwing errors on migrate that can be hard to fix.
For me, this error occurred, because I was swapping a ForeignKey Model from
my_field = models.ForeignKey('old.model', ...)
to
my_field = models.ForeignKey('new.model', ...)
The solution was to edit the resulting migration manually, and add the latest migration from the new
app as a dependency:
class Migration(migrations.Migration):
dependencies = [
('old', '0016_whatever'),
('new', '0002_latest_migration'), # Add this line
]
Try using RenameModel
and RenameField
. See answer here: https://stackoverflow.com/a/26241640/57952
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With