1

I am using SQLAlchemy with ORM and DeclarativeMeta to connect to my Database.

Is there a way to generate or export a .sql file that contains all the Create Tables Commands?

Thank you!

I tried to get that information from my Meta Object or even from my SQLAlchemy Engine but they don't hold information like that.

Even the Meta.metadate._create_all() does not return a string or something else

1 Answer 1

1

Found an answers in the documentation of sqlalchemy.

from sqlalchemy.schema import CreateTable
print(CreateTable(my_mysql_table).compile(mysql_engine))

CREATE TABLE my_table (
id INTEGER(11) NOT NULL AUTO_INCREMENT,
...
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

SQLAlchemy Documentation!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.