我正在运行一个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 seed:run
时,我收到以下错误:
错误:ER_NO_TABLES_USED:未使用表格 在Query.Sequence._packetToError(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ mysql \ lib \ protocol \ sequences \ Sequence.js:52:14) 在Query.ErrorPacket(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ mysql \ lib \ protocol \ sequences \ Query.js:77:18) 在Protocol._parsePacket(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ mysql \ lib \ protocol \ Protocol.js:279:23) 在Parser.write(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ mysql \ lib \ protocol \ Parser.js:76:12) 在Protocol.write(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ mysql \ lib \ protocol \ Protocol.js:39:16) 在Socket。 (C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ mysql \ lib \ Connection.js:103:28) 在emitOne(events.js:115:13) 在Socket.emit(events.js:210:7) 在addChunk(_stream_readable.js:266:12) 在readableAddChunk(_stream_readable.js:253:11) 在Socket.Readable.push(_stream_readable.js:211:10) 在TCP.onread(net.js:585:20) -------------------- 在Protocol._enqueue(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ mysql \ lib \ protocol \ Protocol.js:145:48) 在Connection.query(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ mysql \ lib \ Connection.js:208:25) 在C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ knex \ lib \ dialects \ mysql \ index.js:152:18 在Promise._execute(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ bluebird \ js \ release \ debuggability.js:300:9) 在Promise._resolveFromExecutor(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ bluebird \ js \ release \ promise.js:483:18) 在新的Promise(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ bluebird \ js \ release \ promise.js:79:10) 在Client_MySQL._query(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ knex \ lib \ dialects \ mysql \ index.js:146:12) 在Client_MySQL.query(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ knex \ lib \ client.js:197:17) 在亚军。 (C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ knex \ lib \ runner.js:146:36) 在Runner.tryCatcher(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ bluebird \ js \ release \ util.js:16:23) 在Runner.query(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ bluebird \ js \ release \ method.js:15:34) 在C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ knex \ lib \ runner.js:65:21 在tryCatcher(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ bluebird \ js \ release \ util.js:16:23) 在C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ bluebird \ js \ release \ using.js:185:26 在tryCatcher(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ bluebird \ js \ release \ util.js:16:23) 在Promise._settlePromiseFromHandler(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ bluebird \ js \ release \ promise.js:512:31) 在Promise._settlePromise(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ bluebird \ js \ release \ promise.js:569:18) 在Promise._settlePromise0(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ bluebird \ js \ release \ promise.js:614:10) 在Promise._settlePromises(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ bluebird \ js \ release \ promise.js:693:18) 在Promise._fulfill(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ bluebird \ js \ release \ promise.js:638:18) 在PromiseArray._resolve(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ bluebird \ js \ release \ promise_array.js:126:19) 在PromiseArray._promiseFulfilled(C:\ Users \ user \ Desktop \ Coding Projects \ learning_crud \ node_modules \ bluebird \ js \ release \ promise_array.js:144:14)
有什么建议我做错了吗?
答案 0 :(得分:0)
缺少()
title:faker.lorem.sentence(),
description:faker.lorem.paragraph(),
createdAt:faker.date.past(),
updatedAt:faker.date.recent(),
deletedAt:faker.date.recent(),
已删除:faker.random.boolean(),