Can not created the Datasource with mysql

女生的网名这么多〃 提交于 2019-12-24 08:09:14

问题


I am creating loopback applications with mysql . I set out the datasource will be mysql but when i run the applications i got following error in console windows .

ReferenceError: Cannot create data source "shop": Cannot initialize connector "mysql": time is not defined

Here is my datasource.json code .

{
  "db": {
    "name": "db",
    "connector": "memory"
  },
  "shop": {
    "host": "localhost",
    "port": 8081,
    "url": "",
    "database": "shoppingdatabase",
    "password": "",
    "name": "shop",
    "user": "root",
    "connector": "mysql",
    "connectTimeout":9000000
  }
}

Here is the code for model.json

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "loopback/server/mixins",
      "../common/mixins",
      "./mixins"
    ]
  },
  "User": {
    "dataSource": "db"
  },
  "AccessToken": {
    "dataSource": "db",
    "public": false
  },
  "ACL": {
    "dataSource": "db",
    "public": false
  },
  "RoleMapping": {
    "dataSource": "db",
    "public": false,
    "options": {
      "strictObjectIDCoercion": true
    }
  },
  "Role": {
    "dataSource": "db",
    "public": false
  },
  "carts": {
    "dataSource": "shop",
    "public": true
  },
  "products": {
    "dataSource": "shop",
    "public": true
  },
  "users": {
    "dataSource": "shop",
    "public": true
  },
  "vendors": {
    "dataSource": "shop",
    "public": true
  }
}

Here is the screen shot when i run the server .


回答1:


Change your datasource.json as :

    {
      "db": {
      "host": "localhost",
      "port": 3306,
      "url": "",
      "database": "shoppingdatabase",
      "password": "",
      "name": "db",
      "user": "root",
      "connector": "mysql",
      "connectTimeout":9000000
     }
   }

and model.json as

    {
     "_meta": {
     "sources": [
       "loopback/common/models",
       "loopback/server/models",
       "../common/models",
       "./models"
      ],
     "mixins": [
       "loopback/common/mixins",
       "loopback/server/mixins",
       "../common/mixins",
       "./mixins"
      ]
    },
    "User": {
     "dataSource": "db"
    },
    "AccessToken": {
     "dataSource": "db",
     "public": false
    },
    "ACL": {
     "dataSource": "db",
     "public": false
    },
    "RoleMapping": {
     "dataSource": "db",
     "public": false,
     "options": {
       "strictObjectIDCoercion": true
      }
    },
    "Role": {
     "dataSource": "db",
     "public": false
    },
    "carts": {
     "dataSource": "db",
     "public": true
    },
    "products": {
     "dataSource": "db",
     "public": true
    },
    "users": {
     "dataSource": "db",
     "public": true
    },
    "vendors": {
     "dataSource": "db",
     "public": true
    }
  }

and before that create a database in MySQL manually with the name "shoppingdatabase" as loopback will need the database pre-created. And keep it password protected too.



来源:https://stackoverflow.com/questions/57261932/can-not-created-the-datasource-with-mysql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!