Python Forum
Flask error sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) UNIQUE constraint
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flask error sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) UNIQUE constraint
#3
Hi,

if the unique constrain fails it typcially means that there is already an entry with the exactly same title. As the title has to be unique, you cannot add another book with the same title. This will happen when you run your codes shown twice.

I would also suggest reconsidering making the title alone unique, as it prevents to have two books with the same title but from different authors in the database. You may want to consider to have a combined unique constrain so that title + author have to be unique.

You also may want to rethink your database design for the book table, as it doesn't take under consideration that a book may be written by two or more authors.

Regards, noisefloor
Reply


Messages In This Thread
RE: Flask error sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) UNIQUE constraint - by noisefloor - Feb-21-2023, 03:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Flask: sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) database is locked pythonpaul32 1 2,180 Apr-04-2023, 07:44 AM
Last Post: Larz60+
  Flask and SQLAlchemy question: Database is being created but tables aren't adding pythonpaul32 3 4,891 Feb-07-2023, 10:48 AM
Last Post: pythonpaul32
  Server Error with parse_args() using Flask NoNameoN 0 1,119 Jul-30-2022, 09:42 AM
Last Post: NoNameoN
  [split] flask 500 internal server error DarthTensor 3 4,081 Nov-11-2021, 06:10 AM
Last Post: DarthTensor
  Error updating one to many relationship in Flask/ SQLAlchemy atindra 0 3,375 Apr-15-2021, 10:29 PM
Last Post: atindra
  Flask migrate sqlalchemy not found TomasAm 2 3,528 Dec-01-2020, 10:04 AM
Last Post: TomasAm
  sqlalchemy.exc.IntegrityError: (psycopg2.errors.NotNullViolation) py_kt 3 5,954 Aug-28-2020, 04:47 PM
Last Post: Larz60+
  TemplateNotFound error with flask Veztar 4 18,933 Aug-28-2020, 07:02 AM
Last Post: Veztar
  python 3.7 on windows using flask and flask-sqlalchemy. Alpy 2 4,032 Aug-12-2020, 07:24 PM
Last Post: Alpy
  Flask-Sqlalchemy count products in specific category imawesome 2 32,824 Mar-12-2020, 08:14 PM
Last Post: imawesome

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020