Manuel Leduc
Manuel Leduc

Reputation: 1919

Is the database already created?

I'm currently writing an initialization script for my sqlalchemy database.

And one thing I want to know is if the database has already been created once.
If the database is a sqlite one it's easy, I just have to check if the sqlite file exists, but what about for a postgresql/mysql database ?

So is there a generic way to find out if a database is already created with sqlalchemy ?

Thanks.

Upvotes: 0

Views: 100

Answers (2)

synthesizerpatel
synthesizerpatel

Reputation: 28036

From the docs for sqlalchemy.schema.Metadata.create_all

create_all(bind=None, tables=None, checkfirst=True)

Create all tables stored in this metadata.

Conditional by default, will not attempt to recreate tables already present in the 
target database.

Upvotes: 2

Louis
Louis

Reputation: 2890

This may help you :

CREATE DATABASE [IF NOT EXISTS] db_name
    [create_specification [, create_specification] ...]

from http://dev.mysql.com/doc/refman/5.0/fr/create-database.html

Upvotes: 0

Related Questions