Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migration:refresh command not working properly #81

Closed
alexblunck opened this issue Dec 14, 2016 · 11 comments
Closed

migration:refresh command not working properly #81

alexblunck opened this issue Dec 14, 2016 · 11 comments
Assignees

Comments

@alexblunck
Copy link

Hi,

Running the migration:refresh command always logs the following error: ER_TABLE_EXISTS_ERROR: Table 'deploys' already exists

Here is the related migration class:

'use strict'

const Schema = use('Schema')

class DeploysTableSchema extends Schema {

  up () {
    this.create('deploys', (table) => {
      table.increments()
      table.timestamps()
      table.string('project')
      table.string('commit')
      table.string('environment')
      table.text('output')
    })
  }

  down () {
    this.drop('deploys')
  }

}

module.exports = DeploysTableSchema

It seems like the down method is never called. I've tried this with different drivers (sqlite3, mysql, mysql2) and am having the same problem.

I'm not sure if this is related, but running the migration:reset command always logs: Already at the latest batch. although it should actually be calling down on all migrations if I understand that correctly.

If it helps here is the output of migration:status:

┌───────────────────────────────────┬────────┐
│ Migration                         │ Status │
├───────────────────────────────────┼────────┤
│ 1481658880393_create_deploy_table │ N      │
└───────────────────────────────────┴────────┘

Thanks for all the hard work, I'm just working my way into the framework but am really enjoying using it so far!

@thetutlage
Copy link
Member

thetutlage commented Dec 14, 2016

Would you like to share the screenshot of adonis_migrations table in the database?

@alexblunck
Copy link
Author

Sure, it's called adonis_schema here though:

screen shot 2016-12-14 at 16 29 23

@thetutlage
Copy link
Member

thetutlage commented Dec 14, 2016

Yup identified bug. I changed the behavior of pluck in this d8603d1 commit. Will fix it and rename pluck to something that does not introduce a breaking change.

@thetutlage thetutlage added the bug label Dec 14, 2016
@thetutlage thetutlage self-assigned this Dec 14, 2016
@alexblunck
Copy link
Author

Great, thank you!

@thetutlage
Copy link
Member

Want to give it a try from by installing it from GH?

npm i --save https://github.com/adonisjs/adonis-lucid.git\#develop

@alexblunck
Copy link
Author

Yup, tried it ... all works perfectly now, thanks again!

@leogiouldasis
Copy link

Hello,
I do have the same problem with migration:run also.
The update you posted on Github fixes it.
npm i --save https://github.com/adonisjs/adonis-lucid.git\#develop

Is there going to be an official fix on the framework?

@LaloHao
Copy link

LaloHao commented May 14, 2017

I am still having this issue even with npm i --save https://github.com/adonisjs/adonis-lucid.git\#develop

Error: create table `users` (`id` int unsigned not null auto_increment primary key, `deleted_at` datetime null) - ER_TABLE_EXISTS_ERROR: Table 'users' already exists

@RomainLanz
Copy link
Member

Hey @LaloHao 👋🏼

It may be an issue with a desync of the adonis_schema table and the real state of your database.
May you check the content of adonis_schema table?

@LaloHao
Copy link

LaloHao commented May 14, 2017

Hi @RomainLanz , i do think thats my problem, this is my adonis_schema

+----+----------------------------+-------+---------------------+
| id | name                       | batch | migration_time      |
+----+----------------------------+-------+---------------------+
|  1 | 1494737070625_users        |     1 | 2017-05-14 00:06:41 |
|  2 | 1494737513680_accounts     |     1 | 2017-05-14 00:06:41 |
|  3 | 1494738606442_transactions |     2 | 2017-05-14 00:11:19 |
+----+----------------------------+-------+---------------------+

I just executed ./ace make:migration transactions --create=transactions (new file is 1494776667115_transactions.js) and now it gives me

Error: create table `transactions` (`id` int unsigned not null auto_increment primary key, `amount` int, `description` varchar(255), `created_at` datetime, `updated_at` datetime, `deleted_at` datetime null) - ER_TABLE_EXISTS_ERROR: Table 'transactions' already exists

If i just drop manually the tables ./ace migration:run works

thetutlage added a commit that referenced this issue Jul 16, 2017
change in pluck signature seems to be producing breaking changes, which is not ideal and must be

avoided. Renamed the method to pluckAll

Closes #81
@Karlheinzniebuhr
Copy link

Having the same issue with mysql

[ { sql: 'drop table if exists adonis_schema_lock', bindings: [] } ] { Error: ER_TABLE_EXISTS_ERROR: Table 'comments' already exists at Query.Sequence._packetToError (C:\dev\Work\RyS\TODOer\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14) at Query.ErrorPacket (C:\dev\Work\RyS\TODOer\node_modules\mysql\lib\protocol\sequences\Query.js:77:18) at Protocol._parsePacket (C:\dev\Work\RyS\TODOer\node_modules\mysql\lib\protocol\Protocol.js:278:23) at Parser.write (C:\dev\Work\RyS\TODOer\node_modules\mysql\lib\protocol\Parser.js:76:12) at Protocol.write (C:\dev\Work\RyS\TODOer\node_modules\mysql\lib\protocol\Protocol.js:38:16) at Socket.<anonymous> (C:\dev\Work\RyS\TODOer\node_modules\mysql\lib\Connection.js:91:28) at Socket.<anonymous> (C:\dev\Work\RyS\TODOer\node_modules\mysql\lib\Connection.js:502:10) at Socket.emit (events.js:189:13) at addChunk (_stream_readable.js:284:12) at readableAddChunk (_stream_readable.js:265:11) at Socket.Readable.push (_stream_readable.js:220:10) at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17) -------------------- at Protocol._enqueue (C:\dev\Work\RyS\TODOer\node_modules\mysql\lib\protocol\Protocol.js:144:48) at Connection.query (C:\dev\Work\RyS\TODOer\node_modules\mysql\lib\Connection.js:200:25) at C:\dev\Work\RyS\TODOer\server\node_modules\knex\lib\dialects\mysql\index.js:154:18 at Promise._execute (C:\dev\Work\RyS\TODOer\server\node_modules\bluebird\js\release\debuggability.js:313:9) at Promise._resolveFromExecutor (C:\dev\Work\RyS\TODOer\server\node_modules\bluebird\js\release\promise.js:483:18) at new Promise (C:\dev\Work\RyS\TODOer\server\node_modules\bluebird\js\release\promise.js:79:10) at Client_MySQL._query (C:\dev\Work\RyS\TODOer\server\node_modules\knex\lib\dialects\mysql\index.js:148:12) at Client_MySQL.query (C:\dev\Work\RyS\TODOer\server\node_modules\knex\lib\client.js:202:17) at C:\dev\Work\RyS\TODOer\server\node_modules\knex\lib\transaction.js:272:21 at tryCatcher (C:\dev\Work\RyS\TODOer\server\node_modules\bluebird\js\release\util.js:16:23) at Function.Promise.attempt.Promise.try (C:\dev\Work\RyS\TODOer\server\node_modules\bluebird\js\release\method.js:39:29) at Client_MySQL.trxClient.query (C:\dev\Work\RyS\TODOer\server\node_modules\knex\lib\transaction.js:269:34) at Runner.<anonymous> (C:\dev\Work\RyS\TODOer\server\node_modules\knex\lib\runner.js:146:36) at Runner.tryCatcher (C:\dev\Work\RyS\TODOer\server\node_modules\bluebird\js\release\util.js:16:23) at Runner.query (C:\dev\Work\RyS\TODOer\server\node_modules\bluebird\js\release\method.js:15:34) at Runner.<anonymous> (C:\dev\Work\RyS\TODOer\server\node_modules\knex\lib\runner.js:213:19) code: 'ER_TABLE_EXISTS_ERROR', errno: 1050, sqlMessage: 'Table \'comments\' already exists', sqlState: '42S01', index: 0, sql: 'create table comments (idint unsigned not null auto_increment primary key,user_idint unsigned,task_idint unsigned,commentvarchar(225),created_atdatetime,updated_at datetime)' }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants