I added another field to my Listing()
model called highest_bid
. However, when I try to look at the listing model in the /admin
page I get the OperationalError
:
no such column: auctions_listing.highest_bid
After adding this field I tried using makemigrations
, but it said that there were no changes and I also tried using migrate
but that also said that there was nothing to migrate.
I also tried removing null=True
on the field but that did not change anything.
How do I add this field without getting an error?
models.py:
class Listing(models.Model):
...
highest_bid = models.FloatField()
# highest_bid = models.FloatField(null=True)
# they both returned the same error
CodePudding user response:
According to this answer you have to make sure you:
- Add your app to
INSTALLED_APPS
insidesettings.py
, otherwisemakemigrations
will not check for changes in your models - Run
./manage.py makemigrations <app_name>
if your app doens't have amigrations
module yet (i.e. it's going to be your app's0001_initial.py
migration)
If you can cross these two requirements off your list (i.e. you're doing subsequent changes to your models), then ./manage.py makemigrations
without any <app_name>
should simply work.
CodePudding user response:
how makemigrations
didn't add the changes, you have to find a way to implement make migrations and create a file in the migrations folder otherwise, your field will not be in the DB and you will keep seeing the same error
so try ./manage.py makemigrations your_app_name