gpt4 book ai didi

javascript - knex - 给我错误 : ER_NO_TABLES_USED: No tables used

转载 作者:行者123 更新时间:2023-12-03 03:30:06 25 4
gpt4 key购买 nike

我正在运行 mysql 数据库,并且正在进行以下迁移,该迁移成功运行:

exports.up = function (knex, Promise) {
return knex.schema.createTable('posts', function (t) {
t.increments('id').unsigned().primary();
t.string('title').notNull();
t.text('description').nullable();
t.boolean('deleted').nullable();
t.dateTime('createdAt').notNull();
t.dateTime('updatedAt').nullable();
t.dateTime('deletedAt').nullable();
});
};

exports.down = function (knex, Promise) {
return knex.schema.dropTable('posts');
};

此外,我创建了一个种子文件:

var faker = require('faker');

exports.seed = function (knex, Promise) {
// Deletes ALL existing entries
return knex('posts').del()
.then(function () {
// Inserts seed entries
return knex('posts').insert([{
id: 1,
title: faker.lorem.sentence,
description: faker.lorem.paragraph,
createdAt: faker.date.past,
updatedAt: faker.date.recent,
deletedAt: faker.date.recent,
deleted: faker.random.boolean,

},
]);
});
};

当我运行 knex seeds:run 时,出现以下错误:

Error: ER_NO_TABLES_USED: No tables used at Query.Sequence._packetToError (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14) at Query.ErrorPacket (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\mysql\lib\protocol\sequences\Query.js:77:18) at Protocol._parsePacket (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\mysql\lib\protocol\Protocol.js:279:23) at Parser.write (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\mysql\lib\protocol\Parser.js:76:12) at Protocol.write (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\mysql\lib\protocol\Protocol.js:39:16) at Socket. (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\mysql\lib\Connection.js:103:28) at emitOne (events.js:115:13) at Socket.emit (events.js:210:7) at addChunk (_stream_readable.js:266:12) at readableAddChunk (_stream_readable.js:253:11) at Socket.Readable.push (_stream_readable.js:211:10) at TCP.onread (net.js:585:20) -------------------- at Protocol._enqueue (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\mysql\lib\protocol\Protocol.js:145:48) at Connection.query (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\mysql\lib\Connection.js:208:25) at C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\knex\lib\dialects\mysql\index.js:152:18 at Promise._execute (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\bluebird\js\release\debuggability.js:300:9) at Promise._resolveFromExecutor (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\bluebird\js\release\promise.js:483:18) at new Promise (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\bluebird\js\release\promise.js:79:10) at Client_MySQL._query (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\knex\lib\dialects\mysql\index.js:146:12) at Client_MySQL.query (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\knex\lib\client.js:197:17) at Runner. (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\knex\lib\runner.js:146:36) at Runner.tryCatcher (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\bluebird\js\release\util.js:16:23) at Runner.query (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\bluebird\js\release\method.js:15:34) at C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\knex\lib\runner.js:65:21 at tryCatcher (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\bluebird\js\release\util.js:16:23) at C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\bluebird\js\release\using.js:185:26 at tryCatcher (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\bluebird\js\release\util.js:16:23) at Promise._settlePromiseFromHandler (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\bluebird\js\release\promise.js:512:31) at Promise._settlePromise (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\bluebird\js\release\promise.js:569:18) at Promise._settlePromise0 (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\bluebird\js\release\promise.js:614:10) at Promise._settlePromises (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\bluebird\js\release\promise.js:693:18) at Promise._fulfill (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\bluebird\js\release\promise.js:638:18) at PromiseArray._resolve (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\bluebird\js\release\promise_array.js:126:19) at PromiseArray._promiseFulfilled (C:\Users\user\Desktop\Coding Projects\learning_crud\node_modules\bluebird\js\release\promise_array.js:144:14)

有什么建议我做错了什么吗?

最佳答案

缺少()

标题:faker.lorem.sentence(),

描述:faker.lorem.paragraph(),

创建时间:faker.date.past(),

updatedAt: faker.date.recent(),

deletedAt: faker.date.recent(),

删除:faker.random.boolean(),

关于javascript - knex - 给我错误 : ER_NO_TABLES_USED: No tables used,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46138260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com