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

Could not assemble any primary key when using the SQLModel generator #330

Open
2 tasks done
simkessy opened this issue Jun 4, 2024 · 0 comments
Open
2 tasks done
Labels

Comments

@simkessy
Copy link

simkessy commented Jun 4, 2024

Things to check first

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

Sqlacodegen version

3.0.0rc5

SQLAlchemy version

2.0.30

RDBMS vendor

MySQL (or compatible)

What happened?

I generated the sqlmodel and got something like this for one table:

class ContactDetails(SQLModel, table=True):
    __tablename__ = 'contact_details'

    id: Optional[int] = Field(
        default=None, sa_column=mapped_column("id", Integer, primary_key=True)
    )

But when I try to load this model I get:

File "/usr/local/lib/python3.8/dist-packages/sqlmodel/main.py", line 553, in __init__
    DeclarativeMeta.__init__(cls, classname, bases, dict_, **kw)
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/orm/decl_api.py", line 196, in __init__
    _as_declarative(reg, cls, dict_)
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/orm/decl_base.py", line 244, in _as_declarative
    return _MapperConfig.setup_mapping(registry, cls, dict_, None, {})
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/orm/decl_base.py", line 325, in setup_mapping
    return _ClassScanMapperConfig(
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/orm/decl_base.py", line 579, in __init__
    self._early_mapping(mapper_kw)
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/orm/decl_base.py", line 366, in _early_mapping
    self.map(mapper_kw)
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/orm/decl_base.py", line 1954, in map
    mapper_cls(self.cls, self.local_table, **self.mapper_args),
  File "<string>", line 2, in __init__
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/util/deprecations.py", line 281, in warned
    return fn(*args, **kwargs)  # type: ignore[no-any-return]
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/orm/mapper.py", line 853, in __init__
    self._configure_pks()
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/orm/mapper.py", line 1639, in _configure_pks
    raise sa_exc.ArgumentError(
sqlalchemy.exc.ArgumentError: Mapper Mapper[ContactDetails(contact_details)] could not assemble any primary key columns for mapped table 'contact_details'

I'm using SQLModel v 0.0.19

@simkessy simkessy added the bug label Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant