Auto-create mysql table with StrongLoop

后端 未结 8 988
栀梦
栀梦 2021-02-07 11:39

I am trying to use Strongloop with MySql but cannot figure out how to migrate or automatically create tables into a MySql database.

Is there at least a way to export the

8条回答
  •  耶瑟儿~
    2021-02-07 12:15

    In my case, I manually created MySQL tables and then created the models. For existing MySQL tables, I create the models where property names are the same as MySQL field's names.

    So here are my steps in using StrongLoop LoopBack with MySQL Database:

    1. Create MySQL Database and Tables (or use existing database).
    2. Install MySQL connector using npm install loopback-connector-mysql --save
    3. Add your MySQL Database details on datasources.json file.
    4. Create a model for each table using slc lb model tablename -i OR edit models.json file and add the properties manually. (document: http://docs.strongloop.com/display/DOC/Creating+a+LoopBack+application#CreatingaLoopBackapplication-Creatingmodels)
    5. Properties' names should be the same as MySQL field's names (more information on mapping MySQL to JSON data types: http://docs.strongloop.com/display/DOC/MySQL+connector#MySQLconnector-MySQLtoJSONtypes)

提交回复
热议问题