Comments (9)
For anyone who might be lost like me...
If you're using dotenv, you should require it in config.js
.
const dotenv = require('dotenv').config();
module.exports = {
development: {
database: process.env.DB_NAME,
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
host: process.env.DB_HOST,
port: process.env.DB_PORT,
dialect: 'mysql',
define: {
underscored: true
},
},
}
from cli.
For anyone wondering why sequelize -c my_config.js
doesn't work, the syntax has been updated. Use this instead sequelize --config my_config.js
from cli.
Yeah that would work as well, you only have to tell the CLI to use the js file as configuration file:
sequelize -c my_config.js
from cli.
Hi @anthonator,
there is this thing called use_env_variable
... You can find it here:
Line 191 in ff71914
If I get that right, and please let me know if that is the truth, because we should add that to the docs then, you can do this in your config.json
:
{
"production": {
"use_env_variable": "DB_HOST"
}
}
Having that you can set an env var DB_HOST
to the URL of your database. Not entirely sure how that url looks like though. Please let me know if this helps already. Otherwise I will try to find out one is supposed to use that :D
from cli.
Current version of sequelize-cli supports config.JS by default. All you have to do is write your config.js as this:
require('dotenv').config();
module.exports = {
dev: {
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
host: process.env.DB_HOST,
dialect: 'mysql'
},
"production": {
"username": process.env.DB_USER,
"password": process.env.DB_PASS,
"database": process.env.DB_NAME,
"host": process.env.DB_HOST,
"dialect": "mysql"
}
}
Note - your "dev" parameter name in config.js has to be exactly the same as in your .env file
from cli.
Thanks for the reply @sdepold! I haven't had a chance to try your suggestion yet, but it seems like a rather round about solution when you can write native JavaScript to handle this scenario easily.
module.exports = {
production: {
database: process.env.PG_DATABASE,
host: process.env.PG_HOST,
dialect: 'postgres'
...snip...
}
};
Is there any reason the above wouldn't work? Could simplify the config code (no JSON parsing!).
from cli.
Perfect! Thanks @sdepold! This might be handy in the docs if it's not already there.
from cli.
Is this still a problem or am I wrong? #688
from cli.
There is no config.js
in my installation. Is this to be manually written? I have an automatically created models/index.js
when I ran sequelie init
.
from cli.
Related Issues (20)
- BulkInsert "relation does not exist" in migration script
- const model = require(path.join(__dirname, file)).default( ^ TypeError: require(...).default is not a function
- const model = require(path.join(__dirname, file)).default( ^ TypeError: require(...).default is not a function HOT 1
- Sequelize CLI Fails to Authenticate with Postgres DB Containing a ':' in Password HOT 4
- CLI is not taking default env like node latest versions have (20.8.0)
- SequelizeMeta structure incompatible with SingleStore/memsql HOT 2
- Problem running migrations with yarn
- When on typescript project, sequelize-cli still generates javascript files. HOT 3
- Running migrations, on Azure database HOT 1
- Seeders state in database with using url option
- Migration undo command didn't work correctly. HOT 1
- where condition in literal HOT 1
- nested dependency es5-ext has a security vulnerability (low) and needs update HOT 1
- Subsequent migrations fail after running db:migrate:schema:timestamps:add command
- Please install sqlite3 package manually
- Incompatibility Error with [email protected] and Node.js 21.7.3 HOT 2
- Error: Dialect needs to be explicitly supplied as of v4.0.0 HOT 2
- npx sequelize-cli db:migrate command don't read the environment variables with PM2 HOT 1
- ERROR: Error reading "config\config.js". Error: undefined. Migracion con sequelize-cli HOT 6
- Dialect options being ignored for mssql named instance
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cli.