How to define a table without primary key with SQLAlchemy?

David S. :

I have a table that does not have a primary key. And I really do not want to apply this constraint to this table.

In SQLAlchemy, I defined the table class by:

class SomeTable(Base):
  __table__ = Table('SomeTable', meta, autoload=True, autoload_with=engine)

When I try to query this table, I got:

ArgumentError: Mapper Mapper|SomeTable|SomeTable could not assemble any primary key columns for mapped table 'SomeTable'.

How to loss the constraint that every table must have a primary key?

mta194 :

There is only one way that I know of to circumvent the primary key constraint in SQL Alchemy - it's to map specific column or columns to your table as a primary keys, even if they aren't primary key themselves. http://docs.sqlalchemy.org/en/latest/faq/ormconfiguration.html#how-do-i-map-a-table-that-has-no-primary-key.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to create a table with Interval as primary key in SQLAlchemy?

How to add a primary key to a mysql table without a primary key

EF - How to define foreign key which is the primary key of the current table

How to refer to a record in a table without a primary key

Table without a primary key

SQLAlchemy. How to use the mapper() without a primary key?

How do you define a primary key on a table in Trino?

How should I define a composite primary key for an existing database table?

How to update table with sequentional on table without primary key?

sqlalchemy primary key without auto-increment

how to do hibernate mapping for table or view without a primary key

How to create table without primary key in Entity Framework Core?

How to migrate from table without primary key using room?

how to define primary key , forien key in loopback

create primary key on existing table without primary key in SQL Server

How to delete a row in a table with a primary key, without deleting the value of anothers table Foreign Key?

how to define composite primary key in mybatis mapping

How do you create an association table with an auto increment primary key in SQLAlchemy for Flask?

MS Access query table without primary key

Import CSV without primary key to existing table

Deleting records from a table without primary key

Entity Framework: table without primary key

Delete from table without primary key in Sequel

MySQL table without primary key (best practice)

Find duplicates in table without primary key

Is it possible to create a table in the Room without a primary key?

SQLAlchemy Automap does not create class for tables without primary key

If I create a table without a primary key then add a primary key, is the primary key a clustered index?

SqlAlchemy - How to define a foreign key column using model class instead of physical table name