question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

could not assemble any primary key columns for mapped table

See original GitHub issue

my model:

class Test(db.Model):
    __tablename__ = "Test"  
    STN = db.Column(db.String(3), nullable=False, info='')
    BEG_DATE = db.Column(db.Date, nullable=False, info='')
    END_DATE = db.Column(db.Date, nullable=False, info='')
    PRICE = db.Column(db.String(3), nullable=False, info='')
    REMARK = db.Column(db.String(255), nullable=True, info='')

when I run my flask app, its tips could not assemble any primary key columns for mapped table,Mysql database can create a database without a primary key, Why do I have to set the primary key?I don’t want to set the primary key, how can I solve it?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
zzzeekcommented, Nov 12, 2019

hi there -

please see https://docs.sqlalchemy.org/en/13/faq/ormconfiguration.html#how-do-i-map-a-table-that-has-no-primary-key

if your table has no columns that qualify as a candidate key then it cannot be used by the ORM, you would need to use core only, however, there’s really no such thing in relational databases as a table that doesn’t have a candidate key of some kind, because otherwise it means you can have multiple rows that are complete duplicates of each other, how would that be useful ?

1reaction
danerltcommented, Nov 13, 2019

@zzzeek Thank you for your answer, Eventually I decided to add a primary key to the database table.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not assemble any primary key columns for mapped table
This stops SQLAlchemy from "seeing" that the columns are present, and consequently causes your model not to contain any primary key column.
Read more >
[sqlalchemy] could not assemble any primary key columns for ...
How do I create an ORM type with no primary key columns? For some reason I'm getting: sqlalchemy.exc.ArgumentError: Mapper
Read more >
Mapper could not assemble any primary key columns for ...
Hey, I'm trying to use reflection with SQLAlchemy 0.8 but I always get this exception: sqlalchemy.exc.ArgumentError: Mapper Mapper|links|links could not ...
Read more >
ORM Configuration - SQLAlchemy 1.4 Documentation
How do I map a table that has no primary key?¶ ... The SQLAlchemy ORM, in order to map to a particular table,...
Read more >
sqlalchemy 无primary_key 时报错解决办法could not assemble ...
sqlalchemy 无primary_key 时报错解决办法could not assemble any primary key columns for mapped ... 在大部分表中都会有个自增的id可以作为pk,就不会 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found