mike
mike

Reputation: 49248

What order does SQLAlchemy use for primary key columns?

Let's say I create a table like this:

table = Table('mytable', metadata,
   Column('a', Integer, primary_key=True),
   Column('b', Integer, primary_key=True),
)
table.create()

Is it guaranteed that the primary key will be (a,b) and not (b,a)?

Upvotes: 0

Views: 420

Answers (3)

zzzeek
zzzeek

Reputation: 75297

its guaranteed, yes, since Column objects in Table are ordered. or if you really want to be explicit, use PrimaryKeyContraint().

Upvotes: 5

Sebastian Pipping
Sebastian Pipping

Reputation: 24

USe echo=True and compare yours with a swapped version? That should give the answer.

Upvotes: 0

Pavel Repin
Pavel Repin

Reputation: 30953

Yes. It will be a really bad thing if resulting DDL wasn't giving consistent results.

Upvotes: 0

Related Questions