Using sqlacodegen #
Setup mysql, create user ants ###
shell> mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
mysql> CREATE USER ‘ants'@'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON angir.* TO 'ants'@'localhost' WITH GRANT OPTION;
Import schema from a mwb file ###
Open the mwb file in MySQLWorkbench and export the schema as angir.sql
.
Replace default_schema
with angir
.
shell> mysql -u ants
mysql> create database angir;
mysql> use angir;
mysql> source path/to/angir.sql;
Install sqlacodegen, oursql###
pip install sqlacodegen
pip install oursql
Make models code from the created schema ###
sqlacodegen mysql+oursql://ants:some_pass@localhost/angir > generated_models.py