1๐
As you said in the answers above, the field got manually removed from the database, so the migration tries to delete a field that is no longer existing in the database.
Normally you should never delete fields directly in the db but use the migrations instead. As the field is already gone you can now only fake the migration to tell django that the changes were already made:
manage.py migrate rentals 0002 --fake
Make sure though that you are at migration 0001, otherwise that would be faked aswell.
just to be sure, you could run the following command first:
manage.py migrate rentals 0001
0๐
This type of error means that, there is no any column named phone_image
in the table rental
. So, your second migration is trying to remove a column that is not present in the table rental
. Somehow, you removed that column from the table, and django migration system didnโt notice it.
As a fix try one of these options:
1) delete 0002_remove_rental_phone_image.py
and in 0001_initial.py
remove this line:
('phone_image', models.CharField(blank=True, help_text='image form of the phone number'....))
,
and try to apply migrations (if it says: table rental is already exist
, try to DROP
it from the database);
2) delete all your migration files, and recreate the database, make migrations and apply them.
- Models referring to each other โ how can I most efficiently fix this issue?
- Create a unit test using Django's test client post method passing parameters and requesting JSON from rest_framework
- TimeField and DurationField int error
- Migration in Postgresql and Django 1.8
- Copy/move linked file when changing model instance owner in Django admin
0๐
When you write your code of models.py
then Run Command
python manage.py makemigrations rentals
after this command you will see 0001_any_name.py then Enter again command
python manage.py sqlmigrate rentals 0001 //0001 is prefix of above result
It will create your database accouding to models.py then you can migrate
python manage.pt migrate
So this process run first time when you first time create database but in any database column problem occurs then this above procedure repeat again.your problem will solve.
- Django showing error while saving data into a model: django.db.utils.IntegrityError: (1048, "Column 'id' cannot be null")
- How do I create a wide-format data entry form if data is stored in long form in django