Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Unable to insert using ORM: Instance <...> has a NULL identity key #1152

Copy link
Copy link
Open
@rdong8

Description

@rdong8
Issue body actions

Example:

class Base(DeclarativeBase):
    pass

class User(Base):
    __tablename__ = "users"
    __table_args__ = {"schema": "app"}

    # Not a real column - just here to satisfy SQLAlchemy's requirement for a primary key for every table
    id: Mapped[int] = orm.mapped_column(
        BigInteger, primary_key=True, autoincrement=True
    )

    email: Mapped[Optional[str]] = orm.mapped_column(String)

The following code fails:

engine = create_engine("bigquery://", echo=True)
Base.metadata.create_all(engine)

row = User(email="my@email.com")

with Session(engine) as session:
    with session.begin():
        session.add(row)
FlushError: Instance <User at 0xffff90209d30> has a NULL identity key.  If this is an auto-generated value, check that the database table allows generation of new primary key values, and that the mapped Column object is configured to expect these generated values.  Ensure also that this flush() is not occurring at an inappropriate time, such as within a load() event.

Metadata

Metadata

Labels

api: bigqueryIssues related to the googleapis/python-bigquery-sqlalchemy API.Issues related to the googleapis/python-bigquery-sqlalchemy API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.