現在、新しいテーブルをデータベースに移行しようとしています。このテーブルはユーザテーブルです。これは、2つのエラーを返しユニークな制約関数を持つKnex.jsの移行
exports.up = function(knex, Promise) {
return knex.schema.createTableIfNotExists('users', function(table) {
table.increments('id').primary();
table.string('first_name').notNullable();
table.string('last_name').notNullable();
table.string('email').unique().notNullable();
table.string('password').notNullable();
table.timestamps(false, true);
}).then(() => {
console.log('Users Table is Created!');
})
};
exports.down = function(knex, Promies) {
return knex.schema.dropTable('users')
.then(() => {
console.log('Users Table has been Dropped!');
})
};
:ここで私が持っているコードがある
Knex:warning - migrations failed with error: alter tableusersadd uniqueusers_email_unique(email) - Key column 'email' doesn't exist in table
Error: Key column 'email' doesn't exist in table
何unique()
がやろうとしていることにALTER TABLEをプリフォームであることが表示されます私が作成しようとしているテーブル。したがって、電子メール列が存在しないというエラーです。ここで何か間違っているのですか、テーブルを作成するときに列のunique()
関数を実行できませんか?私は、ドキュメント上のcreateTableでunique()関数を使用する例を見ました。だから私はなぜこれが上記のエラーで返答するのかということを犠牲にしている。
私のデータベースが作成されており、私はそれを見ることができます。 unique()
という制約は、作成されない電子メール列には適用されません。