node.js 从 v4.0.0 开始,需要明确提供方言

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46694157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:32:13  来源:igfitidea点击:

Dialect needs to be explicitly supplied as of v4.0.0

node.jspostgresqlsequelize.js

提问by shumana chowdhury

I have been working on a NodeJS project which uses PostgreSQL database. I am trying to implement migration to the database. Also, using Sequelize. After setting up the migration folder and config, it throws error while running db:migrate

我一直在研究一个使用 PostgreSQL 数据库的 NodeJS 项目。我正在尝试实现到数据库的迁移。另外,使用 Sequelize。设置迁移文件夹和配置后,运行 db:migrate 时抛出错误

The error is: "Dialect needs to be explicitly supplied as of v4.0.0"

错误是:“方言需要从 v4.0.0 开始明确提供”

回答by JPero

Solution for me was based on what I had set for my NODE_ENVvariable.

我的解决方案基于我为NODE_ENV变量设置的内容。

echo $NODE_ENV

echo $NODE_ENV

If you do not have anything set for that variable, try setting it with the following:

如果您没有为该变量设置任何内容,请尝试使用以下内容进行设置:

export NODE_ENV=development

export NODE_ENV=development

If a value ispresent, make sure you have an entry in your config file for thatvalue. For me, I like to use local. So I had to update my config to this:

如果值存在,请确保你在你的config文件中的条目值。对我来说,我喜欢使用local. 所以我不得不将我的配置更新为:

{
 local: {
  username: 'root',
  password: null,
  database: 'database_dev',
  host: '127.0.0.1',
  dialect: 'postgres'
  },
 development: {
  username: 'root',
  password: null,
  database: 'database_dev',
  host: '127.0.0.1',
  dialect: 'postgres'
  },
  test: {
  username: 'root',
  password: null,
  database: 'database_test',
  host: '127.0.0.1',
  dialect: 'postgres'
 },
 production: {
  username: 'root',
  password: null,
  database: 'database',
  host: '127.0.0.1',
  dialect: 'postgres'
 }
}  

回答by Sourav Kumar Behura

Check the dialect once.

检查方言一次。

const Sequelize = require('sequelize'); // Option 1: Passing parameters separately const sequelize = new Sequelize('database', 'username', 'password', { host: 'localhost', dialect: /* one of 'mysql' | 'mariadb' | 'postgres' | 'mssql' */ });

const Sequelize = require('sequelize'); // Option 1: Passing parameters separately const sequelize = new Sequelize('database', 'username', 'password', { host: 'localhost', dialect: /* one of 'mysql' | 'mariadb' | 'postgres' | 'mssql' */ });

回答by Sergiy Voytovych

Check your config file (env names)

检查您的配置文件(环境名称)

{
  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'
  }
}

回答by Murat Ersin

I got same error and I saw this mistake in the code.

我遇到了同样的错误,我在代码中看到了这个错误。

  title: {
    type: Sequelize,
    allowNull: false,
  },

Changed my code with this and problem is solved:

用这个更改了我的代码,问题解决了:

  title: {
    type: Sequelize.STRING,
    allowNull: false,
  },

回答by Mark Hymanson

My issue was that I wasn't pointing to the config file properly. It said "successfully loaded" but I wasn't pointing to the right file.

我的问题是我没有正确指向配置文件。它说“成功加载”,但我没有指向正确的文件。

It should say "Loaded configuration file "[some path]/config.js"."

它应该说“加载的配置文件“[某些路径]/config.js”。

回答by Olawale Isaac

This error can also be caused if there is an error in your model schema.

如果您的模型架构中存在错误,也可能导致此错误。

I had:

我有:

middle_name: { type: Sequelize.Sequelize, allowNull: false, }

middle_name: { type: Sequelize.Sequelize, allowNull: false, }

Which should had been:

应该是:

middle_name: { type: Sequelize.STRING, allowNull: false, }

middle_name: { type: Sequelize.STRING, allowNull: false, }

回答by Napinator

did you forget to add the dialect to your config? see: http://docs.sequelizejs.com/manual/tutorial/migrations.html

您是否忘记将方言添加到您的配置中?请参阅:http: //docs.sequelizejs.com/manual/tutorial/migrations.html

回答by Delino

if you have not setup any .env variables before running your npm server

如果您在运行之前没有设置任何 .env 变量 npm server

You are likely to get that error. so each time you restart app for changes. you will have to export again

您很可能会收到该错误。所以每次你重新启动应用程序进行更改时。你将不得不再次导出

export DATABASE_URL=<your-db-url>