Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlalchemy's create_all doesn't create sequences automatically

I am using SQLAlchemy 0.4.8 with Postgres in order to manage my datastore. Until now, it's been fairly easy to automatically deploy my database: I was using metadata.create_all(bind=engine) and everything worked just fine. But now I am trying to create a sequence that it's not being used by any table, so create_all() doesn't create it, even though it's define correctly: Sequence('my_seq', metadata=myMetadata).

Any thoughts on how I could make this work ?

P.S. And it's not possible at the moment to upgrade to a newer version of SQLAlchemy.

like image 800
hyperboreean Avatar asked Jul 04 '10 14:07

hyperboreean


People also ask

Does Sqlalchemy auto create table?

Creating and Inserting Data into Tables By passing the database which is not present, to the engine then sqlalchemy automatically creates a new database.

What does DB Create_all () do?

Creating and Dropping Database Tables create_all() creates foreign key constraints between tables usually inline with the table definition itself, and for this reason it also generates the tables in order of their dependency.

What does Create_all do in Sqlalchemy?

Sqlalchemy create_all method is used to create a new table into the database. This method will first check whether the table exists in the database or not if suppose it has found an existing table it will not create any table.


1 Answers

Could you call the create it by using its own Sequence.create method:

my_seq = Sequence('my_seq', metadata=myMetadata)
# ...
metadata.create_all(bind=engine)
# @note: create unused objects explicitly
my_seq.create(bind=engine)
# ...
like image 104
van Avatar answered Sep 30 '22 05:09

van