Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple table with no primary key raises error about missing name not key #552

Closed
davidism opened this issue Oct 2, 2017 · 4 comments
Closed
Assignees
Milestone

Comments

@davidism
Copy link
Member

davidism commented Oct 2, 2017

Due to the way __table_cls__ is deciding to create a table, we get the wrong error message when a tablename is generated for a non-inheriting model with no primary key.

class User(db.Model):
    pass

Error is:

sqlalchemy.exc.InvalidRequestError: Class <class '__main__.User'> does not have a __table__ or __tablename__ specified and does not inherit from an existing table-mapped class.

Error should be:

sqlalchemy.exc.ArgumentError: Mapper Mapper|User|user could not assemble any primary key columns for mapped table 'user'
@davidism davidism added this to the 2.3.1 milestone Oct 2, 2017
@davidism davidism self-assigned this Oct 2, 2017
@davidism
Copy link
Member Author

davidism commented Oct 2, 2017

Possible solution: add a check after primary key loop to see if a base class is a mapped model and if not, create the table anyway, instead of unconditionally deleting the name.

@JacobSMoller
Copy link

JacobSMoller commented Oct 4, 2017

Running 2.3.0 i get the does not have a __table__ or __tablename__ even though my class looks like:

class Account(db.Model):
    __tablename__ = 'account'

Works with 2.2

@davidism
Copy link
Member Author

davidism commented Oct 4, 2017

The only way that could have worked is if the table account was already defined, such as from reflection. See #550, fixed by #551.

You have to have one of the following: an existing table with that name, a primary key, or an inherited model.

@JacobSMoller
Copy link

Its reflected, will look at it after #551 is released. Thanks a ton for the quick answer and your work on this project.

@davidism davidism closed this as completed Oct 4, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants