[Fixed]-OperationalError at /admin/rentals/rental/

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
๐Ÿ‘คTim

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.

๐Ÿ‘คsehrob

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.

๐Ÿ‘คNeeraj Kumar

Leave a comment