Migration/MariaSQL problem


#1

When running adonis migration:run with default migrations, it produces error: Error: Unknown column ‘NaN’ in ‘field list’

Debug output:
[ { sql: ‘select * from information_schema.tables where table_name = ? and table_schema = database()’,
bindings: [ ‘adonis_schema’ ],
output: [Function: output] } ]
[ { sql: ‘create table adonis_schema (id int unsigned not null auto_increment primary key, name varchar(255), batch int, migration_time timestamp default CURRENT_TIMESTAMP)’,
bindings: [] } ]
[ { sql: ‘select * from information_schema.tables where table_name = ? and table_schema = database()’,
bindings: [ ‘adonis_schema_lock’ ],
output: [Function: output] } ]
[ { sql: ‘create table adonis_schema_lock (id int unsigned not null auto_increment primary key, is_locked boolean)’,
bindings: [] } ]
{ method: ‘first’,
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ 1, 1 ],
__knexQueryUid: ‘403e39d3-9012-45a3-b9b1-afa0cad7c0d8’,
sql: ‘select * from adonis_schema_lock where is_locked = ? order by id desc limit ?’ }
{ method: ‘insert’,
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ true ],
__knexQueryUid: ‘1919ce39-94db-4603-835a-d86a053d6c39’,
sql: ‘insert into adonis_schema_lock (is_locked) values (?)’ }
{ method: ‘pluck’,
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [],
__knexQueryUid: ‘9ca70218-cbef-42f0-9625-5237366161c3’,
sql: 'select name from adonis_schema',
pluck: ‘name’ }
{ method: ‘select’,
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [],
__knexQueryUid: ‘be309263-71c0-4551-a10c-e9438fa40d2d’,
sql: 'select max(batch) as batch from adonis_schema’ }
[ { sql: ‘create table users (id int unsigned not null auto_increment primary key, username varchar(80) not null, email varchar(254) not null, password varchar(60) not null, created_at datetime, updated_at datetime)’,
bindings: [] },
{ sql: ‘alter table users add unique users_username_unique(username)’,
bindings: [] },
{ sql: ‘alter table users add unique users_email_unique(email)’,
bindings: [] } ]
{ method: ‘insert’,
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ NaN, ‘1523518489744_user’ ],
__knexQueryUid: ‘e800fa83-cbe7-416c-b029-7ee03a88dc65’,
sql: ‘insert into adonis_schema (batch, name) values (?, ?)’ }
[ { sql: 'drop table if exists adonis_schema_lock',
bindings: [] } ]
{ Error: Unknown column ‘NaN’ in ‘field list’

Users and adonis_schema tables are created, but problems seems to be inserting record of users table to adonis_schema table? Any suggestions? Platform Windows10, MariaDB 10.02 x64


#2

Got it working by inserting dummy data to adonis_schema table with batch value 0. Problem seems to be that when there are no records in adonis_schema table, max(batch) returns NaN instead of 0. (at least on my dev setup)


#3

Probably worth raising a GitHub issue with Knex.js as that is what powers the migrations.