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

Migrations table not being created with MySQL datasource #3

Open
antonsamper opened this issue Feb 7, 2016 · 7 comments
Open

Migrations table not being created with MySQL datasource #3

antonsamper opened this issue Feb 7, 2016 · 7 comments

Comments

@antonsamper
Copy link

It looks like this components is currently only working properly when using the in memory datasource.

I have tried changing the datasource to MySQL and i'm getting errors because the table doesnt exist.

@mrfelton
Copy link

mrfelton commented Feb 7, 2016

Gry @antonsamper Which table doesn't exist? Can you paste the specific error that you are seeing? Thanks.

@antonsamper
Copy link
Author

It's the table that saves the migration information. db name is test

Error retrieving migrations:
Error: ER_NO_SUCH_TABLE: Table 'test.migration' doesn't exist
    at Query.Sequence._packetToError (/Users/antonsamper/WebstormProjects/test-project/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:48:14)
    at Query.ErrorPacket (/Users/antonsamper/WebstormProjects/test-project/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/sequences/Query.js:83:18)
    at Protocol._parsePacket (/Users/antonsamper/WebstormProjects/test-project/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/Protocol.js:280:23)
    at Parser.write (/Users/antonsamper/WebstormProjects/test-project/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/Parser.js:73:12)
    at Protocol.write (/Users/antonsamper/WebstormProjects/test-project/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/Users/antonsamper/WebstormProjects/test-project/node_modules/loopback-connector-mysql/node_modules/mysql/lib/Connection.js:96:28)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:146:16)
    at Socket.Readable.push (_stream_readable.js:110:10)
    --------------------
    at Protocol._enqueue (/Users/antonsamper/WebstormProjects/test-project/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/Protocol.js:141:48)
    at PoolConnection.query (/Users/antonsamper/WebstormProjects/test-project/node_modules/loopback-connector-mysql/node_modules/mysql/lib/Connection.js:201:25)
    at runQuery (/Users/antonsamper/WebstormProjects/test-project/node_modules/loopback-connector-mysql/lib/mysql.js:146:16)
    at executeWithConnection (/Users/antonsamper/WebstormProjects/test-project/node_modules/loopback-connector-mysql/lib/mysql.js:188:7)
    at Ping.onOperationComplete (/Users/antonsamper/WebstormProjects/test-project/node_modules/loopback-connector-mysql/node_modules/mysql/lib/Pool.js:99:5)
    at Ping.<anonymous> (/Users/antonsamper/WebstormProjects/test-project/node_modules/loopback/node_modules/continuation-local-storage/context.js:76:17)
    at bound (domain.js:287:14)
    at Ping.runBound [as _callback] (domain.js:300:12)
    at Ping.Sequence.end (/Users/antonsamper/WebstormProjects/test-project/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
    at Ping.Sequence.OkPacket (/Users/antonsamper/WebstormProjects/test-project/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:105:8)
No new migrations to run.

@antonsamper
Copy link
Author

@mrfelton are you able to replicate the problem?

@gholias
Copy link

gholias commented Feb 17, 2016

I'm having the same problem, the model Migration is not been created

@frzkhan
Copy link

frzkhan commented Feb 4, 2017

when will these changes be added to master? im having the same problem

@phil-hawkins
Copy link

Same problem occurs with the mssql connector:

Error retrieving migrations: RequestError: Invalid object name 'dbo.Migration'. at C:\Users\Administrator\Source\Repos\BBNEXT\node_modules\loopback-connector-mssql\node_modules\mssql\lib\tedious.js:739:17 at emitOne (events.js:96:13) at Connection.emit (events.js:188:7) at Parser.<anonymous> (C:\Users\Administrator\Source\Repos\BBNEXT\node_modules\loopback-connector-mssql\node_modules\mssql\node_modules\tedious\lib\connection.js:204:16) at emitOne (events.js:96:13) at Parser.emit (events.js:188:7) at Parser.<anonymous> (C:\Users\Administrator\Source\Repos\BBNEXT\node_modules\loopback-connector-mssql\node_modules\mssql\node_modules\tedious\lib\token\token-stream-parser.js:42:15) at emitOne (events.js:96:13) at Parser.emit (events.js:188:7) at readableAddChunk (C:\Users\Administrator\Source\Repos\BBNEXT\node_modules\loopback-connector-mssql\node_modules\mssql\node_modules\tedious\node_modules\readable-stream\lib\_stream_readable.js:210:18) at Parser.Readable.push (C:\Users\Administrator\Source\Repos\BBNEXT\node_modules\loopback-connector-mssql\node_modules\mssql\node_modules\tedious\node_modules\readable-stream\lib\_stream_readable.js:169:10) at Parser.Transform.push (C:\Users\Administrator\Source\Repos\BBNEXT\node_modules\loopback-connector-mssql\node_modules\mssql\node_modules\tedious\node_modules\readable-stream\lib\_stream_transform.js:123:32) at doneParsing (C:\Users\Administrator\Source\Repos\BBNEXT\node_modules\loopback-connector-mssql\node_modules\mssql\node_modules\tedious\lib\token\stream-parser.js:87:17) at C:\Users\Administrator\Source\Repos\BBNEXT\node_modules\loopback-connector-mssql\node_modules\mssql\node_modules\tedious\lib\token\infoerror-token-parser.js:46:5 at C:\Users\Administrator\Source\Repos\BBNEXT\node_modules\loopback-connector-mssql\node_modules\mssql\node_modules\tedious\lib\token\infoerror-token-parser.js:13:19 at C:\Users\Administrator\Source\Repos\BBNEXT\node_modules\loopback-connector-mssql\node_modules\mssql\node_modules\tedious\lib\token\stream-parser.js:224:9 No new migrations to run. undefined

@boeserwolf
Copy link

boeserwolf commented Nov 27, 2017

Hi, for everyone running into the same issue, you could just run autoupdate like so:

let dataSource = app.dataSources['mysql']
dataSource.autoupdate('Migration', function(error) { ... })

Here's a brief example, you could place it in server/boot/migrations.js:

const loopback = require('loopback')

module.exports = function (app, next) {
  const Migration = loopback.getModel('Migration');
  if (!Migration) {
    console.log('Model "Migration" is missing, won\'t execute migrations!');
    return next();
  }

  // Make sure Migrations table exists, "autoupdate" won't touch any data.
  const dataSource = app.dataSources.mysql;
  dataSource.autoupdate('Migration', function (error) {
    // FIXME: Handle errors.
    Migration.migrate('up', function(error) {
      // FIXME: Handle errors.
      console.log('Migrations done.');
      next();
    });
  });

};

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