admin管理员组文章数量:1394740
When I run knex migrate: latest, I get the following, "Already up to date".
You see, I previously ran successful migrations, but then I used the mySQL CLI to delete those tables, because I was getting this 'Already up to date' message. I thought deleting the tables would force knex to recognize it wasn't up to date. Didn't work.
Any pointers?
Here are my files:
knexfile.js:
require('dotenv').config();
module.exports = {
development: {
client: 'mysql',
connection: {
host: process.env.DATABASE_HOST_DEV || '127.0.0.1',
user: process.env.DATABASE_USER_DEV,
password: process.env.DATABASE_PASSWORD_DEV,
database: process.env.DATABASE_NAME_DEV
},
migrations: {
directory: __dirname+'/database/migrations'
}
},
staging: {
client: 'mysql',
connection: {
host: '127.0.0.1',
user: 'root',
password: 'password',
database: 'recipes'
},
pool: {
min: 2,
max: 10
},
migrations: {
directory: __dirname+'/database/migrations'
}
},
production: {
client: 'mysql',
connection: {
host: process.env.DATABASE_HOST,
user: process.env.DATABASE_USER,
password: process.env.DATABASE_PASSWORD,
database: process.env.DATABASE_NAME
},
pool: {
min: 2,
max: 10
},
migrations: {
directory: __dirname+'/database/migrations'
}
}
};
Migrations:
exports.up = function(knex, Promise) {
return Promise.all([
knex.schema.hasTable('recipe').then((exists) => {
if (!exists) {
knex.schema.createTable('recipe', (table) => {
table.uuid('id');
table.string('name');
table.string('description');
})
}
}),
knex.schema.hasTable('ingredient').then((exists) => {
if (!exists) {
knex.schema.createTable('ingredient', (table) => {
table.uuid('id');
table.string('name');
})
}
}),
knex.schema.hasTable('recipe-ingredient').then((exists) => {
if (!exists) {
knex.schema.createTable('recipe-ingredient', (table)=> {
table.foreign('recipe_id').references('recipe.id');
table.foreign('ingredient_id').references('ingredient.id');
table.string('qty'); // <-- chose string instead of int because receipes include qty such as '1/3 cup', '1 teaspoon', etc.
})
}
})
])
};
exports.down = function(knex, Promise) {
return Promise.all([
knex.schema.dropTable('recipe-ingredient'),
knex.schema.dropTable('ingredient'),
knex.schema.dropTable('recipe')
])
};
When I run knex migrate: latest, I get the following, "Already up to date".
You see, I previously ran successful migrations, but then I used the mySQL CLI to delete those tables, because I was getting this 'Already up to date' message. I thought deleting the tables would force knex to recognize it wasn't up to date. Didn't work.
Any pointers?
Here are my files:
knexfile.js:
require('dotenv').config();
module.exports = {
development: {
client: 'mysql',
connection: {
host: process.env.DATABASE_HOST_DEV || '127.0.0.1',
user: process.env.DATABASE_USER_DEV,
password: process.env.DATABASE_PASSWORD_DEV,
database: process.env.DATABASE_NAME_DEV
},
migrations: {
directory: __dirname+'/database/migrations'
}
},
staging: {
client: 'mysql',
connection: {
host: '127.0.0.1',
user: 'root',
password: 'password',
database: 'recipes'
},
pool: {
min: 2,
max: 10
},
migrations: {
directory: __dirname+'/database/migrations'
}
},
production: {
client: 'mysql',
connection: {
host: process.env.DATABASE_HOST,
user: process.env.DATABASE_USER,
password: process.env.DATABASE_PASSWORD,
database: process.env.DATABASE_NAME
},
pool: {
min: 2,
max: 10
},
migrations: {
directory: __dirname+'/database/migrations'
}
}
};
Migrations:
exports.up = function(knex, Promise) {
return Promise.all([
knex.schema.hasTable('recipe').then((exists) => {
if (!exists) {
knex.schema.createTable('recipe', (table) => {
table.uuid('id');
table.string('name');
table.string('description');
})
}
}),
knex.schema.hasTable('ingredient').then((exists) => {
if (!exists) {
knex.schema.createTable('ingredient', (table) => {
table.uuid('id');
table.string('name');
})
}
}),
knex.schema.hasTable('recipe-ingredient').then((exists) => {
if (!exists) {
knex.schema.createTable('recipe-ingredient', (table)=> {
table.foreign('recipe_id').references('recipe.id');
table.foreign('ingredient_id').references('ingredient.id');
table.string('qty'); // <-- chose string instead of int because receipes include qty such as '1/3 cup', '1 teaspoon', etc.
})
}
})
])
};
exports.down = function(knex, Promise) {
return Promise.all([
knex.schema.dropTable('recipe-ingredient'),
knex.schema.dropTable('ingredient'),
knex.schema.dropTable('recipe')
])
};
Share
Improve this question
asked Jun 18, 2018 at 22:24
208_man208_man
1,7388 gold badges40 silver badges70 bronze badges
3
-
A little extra info: I manually deleted my database using the MySQL CLI. then when I run the latest migration, it appears to run:
Batch 1 run: 4 migrations
. BUT, when I execute "show tables" via MySQL CLI, it only shows the `knex_migrations' and the 'knex_migrations_lock' tables. – 208_man Commented Jun 18, 2018 at 22:39 -
If the cli for
knex
is like that ofsequelize
, it might keep track of which migrations have been run in some sort ofmigrations
table (perhaps theknex_migrations
?). Perhapsknex
is looking at all of your available migration files, recognizing that they all have entries in yourknex_migrations
table, and refusing to run them. I wonder if you change the name of your migration file or try to manually delete its entry inknex_migrations
(if it's there), if knex will run the migration file for you again. – therobinkim Commented Jun 19, 2018 at 4:02 - @therobinkim thanks Robin. I've finally learned that when this happens, I need to delete the records in the knex_migrations table, and delete the migration files in the repo, create new migration files, and run them. This seems to work. – 208_man Commented Jun 19, 2018 at 16:24
1 Answer
Reset to default 8You may need to delete the logs of any migrations with the same name as the previous as your current migration in question, I had the same issue on postgres a while back.
本文标签: javascriptknexjsmigrate latest 39Already Up To Date39Stack Overflow
版权声明:本文标题:javascript - knex.js - migrate latest 'Already Up To Date' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744104304a2590994.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论