I am currently working on a CS50 Web development SQL, Models, and Migrations and following what the tutorial says to do , yet I found that I am not able to duplicate the result at some points.
I have created a new class in models.py named Airport.
class Airport(models.Model):
code = models.CharField(max_length=3)
city = models.CharField(max_length=64)
def __str__(self):
return f"{self.city} ({self.code})"
When I try to use the f = Airport(code="NY", city="New York") f.save() function to save it, the following error occurs
django.db.utils.OperationalError: no such table: flights_airport
I have checked some solutions from the internet, the first one is to do the migration again. Yet, when I do python manage.py makemigrations
it says
No changes detected
when I do python manage.py migrate, it shows a long error message with
django.db.utils.IntegrityError: The row in table 'flights_flight' with primary key '1' has an invalid foreign key:
flights_flight.origin_id contains a value 'new york' that does not have a corresponding value in flights_airport.id
I have also tried to delete all the data with Airport.objects.all().delete()
It again shows the following error code
django.db.utils.OperationalError: no such table: flights_airport
I am stuck in a point that I cant do migration nor can I start it again. I'd like to know what shall I do