admin管理员组文章数量:1336398
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.
When I run python manage.py migrate this appears.
This is the code:
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'airline.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"fet to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
I tried to write another value for New York but it doesn't work either
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.
When I run python manage.py migrate this appears.
This is the code:
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'airline.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"fet to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
I tried to write another value for New York but it doesn't work either
Share Improve this question edited Nov 20, 2024 at 17:59 Compo 38.7k5 gold badges31 silver badges45 bronze badges asked Nov 20, 2024 at 8:14 user28239646user28239646 1 2- 3 Please do not upload images of code/data/errors. – MatBailie Commented Nov 20, 2024 at 8:26
- 1 The error message says it all. You tried to insert a flight from a non-existing airport. – jarlh Commented Nov 20, 2024 at 8:27
1 Answer
Reset to default -1It seems the origin_id
column in the flights_flight
table references the primary key of the flights_airport
table. The value 'New York' in flights_flight.origin_id
does not correspond to any valid id in the flights_airport
table.
So, ensure your foreign key relationship code in your modles.py
, or check your data in your flights_flight
table, maybe delete the row where flights_flight.origin_id = 'New York'
本文标签: pythonwhy SGL give me djanfodbutilsintegrityError idk what that meansStack Overflow
版权声明:本文标题:python - why SGL give me djanfo.db.utils.integrityError ?idk what that means - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742372395a2462490.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论