3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Using sqlacodegen

Last updated at Posted at 2015-04-12

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
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?