Posts: 0
Threads: 0
Joined: Feb 2021
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
If you are facing this error then,you have to add additional argument after **password_for_rootUser** in form of object and need to specify these property according to your RDBMS
```
var Sequilize=require('sequelize');
var connection =new Sequilize('db_name','root_user_name','password_for_rootUser',{
host:'localhost',
dialect:'mysql'|'mariadb'|'sqlite'|'postgress'|'mssql',
pool:{
max:5,
min:0,
idle:10000
},
//for sqlite only
storage:path/to/database.sqlite
});
var Article=connection.define('tableName',{
title:Sequilize.STRING, // your cloumn name with data type
body:Sequilize.TEXT // your cloumn name with data type
});
connection.sync();
```
hope this solves your problem
|
Posts: 0
Threads: 0
Joined: Dec 2019
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
In my case issue was the way I was exporting config from config.ts
`export const = {}` did not work
but `module.exports` worked:
module.exports = {
development: {
dialect: process.env.DB_DIALECT,
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME_DEVELOPMENT,
host: process.env.DB_HOST,
port: process.env.DB_PORT,
},
test: {
dialect: process.env.DB_DIALECT,
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME_DEVELOPMENT,
host: process.env.DB_HOST,
port: process.env.DB_PORT,
},
production: {
dialect: process.env.DB_DIALECT,
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME_DEVELOPMENT,
host: process.env.DB_HOST,
port: process.env.DB_PORT,
},
};
|
Posts: 0
Threads: 0
Joined: Mar 2022
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
I had a `config.js` file from a previous project with a non-standard value for my environment.
It was called `current`.
I changed it to `development` and the error went away.
const main = require('./main');
module.exports = {
development: { // this was set to `current` in my case, and it was causing the error
username: main.db.user,
password: main.db.password,
database: main.db.name,
host: main.db.host,
port: main.db.port || 3306,
dialect: 'mysql'
}
};
|
Posts: 0
Threads: 0
Joined: Dec 2017
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
You can fix this by running this command
export NODE_ENV=development; npx sequelize db:migrate
cheers!
|
Posts: 0
Threads: 0
Joined: Apr 2018
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
In my case, I forgot to uncomment the `DB_CONNECTION` value from `.env` which is used to establish postgreSQL connection in my code
|
Posts: 0
Threads: 0
Joined: Nov 2021
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
After pulling my hair out for a couple hours, I realized I was doing `cd src; node app.js` when really I was supposed to do `node src/app.js`... Gooooooodness
|
Posts: 0
Threads: 0
Joined: May 2021
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
I was facing this error, as it turns out, because of typescipt's transformation/compilation.
A little background: I am using sequelize in a typescript project. And the database config file was in a `database.ts` file.
```javascript
const config = {
development: {
username: env.PG_USERNAME,
password: env.PG_PASSWORD,
database: 'sample_db',
host: env.PG_HOST,
port: env.PG_PORT,
dialect: 'postgres',
},
test: {
username: env.PG_USERNAME,
password: env.PG_PASSWORD,
database: 'sample_db',
host: env.PG_HOST,
port: env.PG_PORT,
dialect: 'postgres',
},
production: {
username: env.PG_USERNAME,
password: env.PG_PASSWORD,
database: 'sample_db',
host: env.PG_HOST,
port: env.PG_PORT,
dialect: 'postgres',
},
};
export default config;
```
In `.sequelizerc` file, I was pointing to the transpiled version of the `database.ts` file i.e. the `dist/config/database.js` file. As shown below:
```
const path = require('path');
module.exports = {
env: process.env.NODE_ENV || 'development',
config: path.resolve('dist', 'config', 'database.js'),
...
};
```
But after inspecting the transpiled version of the `database.ts` file, i noticed that the config was exported as:
```
module.exports.default = config
```
But `sequelize` is expecting the config to be at `module.exports`.
So, I modified the `database.ts` file by appending this one line to the end of the file and that resolved it for me.
```
...
module.exports = config;
```
|
Posts: 0
Threads: 0
Joined: Dec 2018
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
After reading through all the answers and possible solutions to problems people had and nothing worked for me here is another additional solution for an environment that uses:
- **Typescript** (Having the sequelize config in .ts)
- **Sequelize**
Problem: **Not being able to run "sequelize db:migrate"** (getting the error from this thread) **due to sequelize not getting access to the .env file and cannot properly read the config**
Example config
<pre><code>
config: any = {
"development": {
"username": dbUser,
"password": dbPassword,
...
module.exports = config
</pre></code>
**dbUser** is undefined for Sequelize
1. Create a ".sequelizerc" file in the root of your project and give it the path to the already built .js config file:
<pre><code>
const path = require('path');
module.exports = {
'config': path.resolve('./dist', 'src/config/config.js')
};
</pre></code>
2. In your config file add
<pre><code>
module.exports = config
</pre></code>
as sequelize does not like ***export default config*** (as mentioned above). I have both types of exports.
3. Install the dotenv-cli (I did it as a dev dependency, but globally should work fine as well)
4. Run the migration command while suppling the .env file with:
***npx dotenv -e /path/to/.env sequelize db:migrate***
Also had to make sure my NODE_ENV is set to development:
***export NODE_ENV=development***
|
Posts: 0
Threads: 0
Joined: May 2018
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
Check your config file (env names)
<!-- language: lang-json -->
{
development: {
username: 'root',
password: null,
database: 'database_development',
host: '127.0.0.1',
dialect: 'mysql'
},
test: {
username: 'root',
password: null,
database: 'database_test',
host: '127.0.0.1',
dialect: 'mysql'
},
production: {
username: 'root',
password: null,
database: 'database_production',
host: '127.0.0.1',
dialect: 'mysql'
}
}
|
Posts: 0
Threads: 0
Joined: Apr 2023
Reputation:
0
Level: inf []
Total Points: inf
Rank nan / 1
100% to upload Level
Activity inf / 1
99% to upload your Rank
Experience nan
100% to upload Experience
Points: 50
|
use below code in config/config.js to load env
import dotenv from 'dotenv'
dotenv.config()
my .sequelizerc
module.exports = {
'config': path.resolve('config', 'sequelize.js'),
'models-path': path.resolve('src', 'models'),
'seeders-path': path.resolve('src', 'seeders'),
'migrations-path': path.resolve('src', 'migrations')
};
and config/sequelize.js
import dotenv from 'dotenv'
dotenv.config()
export default {
development: {
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
host: process.env.DB_HOST,
port: process.env.DB_PORT,
dialect: process.env.DB_DIALECT,
dialectOptions: {
bigNumberStrings: true
}
},
test: {
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
host: process.env.DB_HOST,
port: process.env.DB_PORT,
dialect: process.env.DB_DIALECT,
},
production: {
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
host: process.env.DB_HOST,
port: process.env.DB_PORT,
dialect: process.env.DB_DIALECT,
dialectOptions: {
bigNumberStrings: true,
}
}
};
|
|