How to add configuration that Strapi use mysql in production and sqlite for local development?
Strapi v4
CodePudding user response:
- Add mysql driver
yarn add mysqlornpm install mysql - Add dotenv
yarn add dotenvornpm install dotenv - Create new file:
config/env/production/database.js - Add the following content:
module.exports = ({ env }) => ({ connection: { client: "mysql", connection: { host: env("DATABASE_HOST", "localhost"), port: env("DATABASE_PORT", 3306), database: env("DATABASE_NAME", "default"), user: env("DATABASE_USERNAME", "root"), password: env("DATABASE_PASSWORD", ""), }, useNullAsDefault: true, }, });
- Add your config to the .env File in Production.
- Strapi will pick the correct configuration.
CodePudding user response:
1.Add MySQL driver npm install mysql
2.Add sqlite3 driver npm install sqlite3
3.Set you environment file we do it like this
3.1. On dev set ENV_PATH= 