Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 447 Vote(s) - 3.42 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dialect needs to be explicitly supplied as of v4.0.0

#11
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
Reply

#12
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,
},
};
Reply

#13
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'
}
};

Reply

#14
You can fix this by running this command

export NODE_ENV=development; npx sequelize db:migrate

cheers!
Reply

#15
In my case, I forgot to uncomment the `DB_CONNECTION` value from `.env` which is used to establish postgreSQL connection in my code
Reply

#16
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
Reply

#17
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;
```
Reply

#18
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***

Reply

#19
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'
}
}
Reply

#20
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,
}
}
};

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through