Invalid Semantics
Here, we’ll discuss an example of an invalid semantic.
In SQLAlchemy, it’s possible to use foreign keys, relationships, and constraints to prevent many of the issues described in the previous lesson.
Example database
For reference, here are the table definitions and initial values without all of the extra steps.
Press + to interact
from sqlalchemy import create_engine, Column, typesfrom sqlalchemy.ext.declarative import declarative_basefrom sqlalchemy.orm import sessionmakerconnection_string = "sqlite:///database.db" # for SQLite, local filedb = create_engine(connection_string)base = declarative_base()class Book(base):__tablename__ = 'books'id = Column(types.Integer, primary_key=True)author = Column(types.String(length=50))title = Column(types.String(length=120), nullable=False)available = Column(types.Boolean, nullable=False)class BirthYear(base):__tablename__ = 'birth_years'author = Column(types.String(length=50), primary_key=True)birth_year = Column(types.Integer, nullable=False)
As the tables are now, there is ...
Access this course and 1400+ top-rated courses and projects.