首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >达特渡槽服务器数据库升级:与数据库连接错误

达特渡槽服务器数据库升级:与数据库连接错误
EN

Stack Overflow用户
提问于 2019-05-13 21:12:55
回答 1查看 1.3K关注 0票数 0

我正在为我的渡槽服务器建立一个PostgreSQL数据库。我用psql创建了一个用户和数据库

代码语言:javascript
复制
CREATE DATABASE words;
CREATE USER words_user WITH createdb;
ALTER USER words_user WITH password 'password';
GRANT all ON database words TO words_user;

我的模型课是

代码语言:javascript
复制
import 'package:demo/demo.dart';

class Word extends ManagedObject<_Word> implements _Word {

}

class _Word {
  @primaryKey
  int id;

  @Column(unique: true)
  String word;

  @Column()
  String info;
}

我生成了一个迁移文件

代码语言:javascript
复制
aqueduct db generate

即:

代码语言:javascript
复制
import 'dart:async';
import 'package:aqueduct/aqueduct.dart';

class Migration1 extends Migration {
  @override
  Future upgrade() async {
    database.createTable(SchemaTable("_Word", [
      SchemaColumn("id", ManagedPropertyType.bigInteger,
          isPrimaryKey: true,
          autoincrement: true,
          isIndexed: false,
          isNullable: false,
          isUnique: false),
      SchemaColumn("word", ManagedPropertyType.string,
          isPrimaryKey: false,
          autoincrement: false,
          isIndexed: false,
          isNullable: false,
          isUnique: true),
      SchemaColumn("info", ManagedPropertyType.string,
          isPrimaryKey: false,
          autoincrement: false,
          isIndexed: false,
          isNullable: false,
          isUnique: false)
    ]));
  }

  @override
  Future downgrade() async {}

  @override
  Future seed() async {
    final rows = [
      {'word': 'horse', 'info': 'large animal you can ride'},
      {'word': 'cow', 'info': 'large animal you can milk'},
      {'word': 'camel', 'info': 'large animal with humps'},
      {'word': 'sheep', 'info': 'small animal with wool'},
      {'word': 'goat', 'info': 'small animal with horns'},
    ];

    for (final row in rows) {
      await database.store.execute(
          "INSERT INTO _Word (word, info) VALUES (@word, @info)",
          substitutionValues: {
            "word": row['word'],
            "info": row['info'],
          });
    }
  }
}

但是现在,当我试图将迁移应用到

代码语言:javascript
复制
aqueduct db upgrade --connect postgres:password@localhost:5432/words

我知道错误:

*连接到数据库'null:null@:0/null‘时出错。原因:无法连接到数据库。

我在源代码中跟踪这条来自这里的错误消息。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-13 21:12:55

结果证明这是一个简单的解决办法。我没有在CLI升级命令中包含数据库用户名。

代码语言:javascript
复制
aqueduct db upgrade --connect postgres://words_user:password@localhost:5432/words

我通过比较我在文档中所写的例子找到了它。

另一次,当我忘记使用正确的数据库名时,也出现了类似的错误。还有一次我在密码前有一个空格。记住要包括所有部件,并确保所有的格式都是正确的。一般格式是

代码语言:javascript
复制
aqueduct db upgrade --connect postgres://username:password@host:port/databaseName

您可以通过键入CLI命令获得帮助

代码语言:javascript
复制
aqueduct db --help
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56119944

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档