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

MSSQL Issue #82

Closed
alexblunck opened this issue Dec 17, 2016 · 10 comments
Closed

MSSQL Issue #82

alexblunck opened this issue Dec 17, 2016 · 10 comments
Assignees

Comments

@alexblunck
Copy link

I'm trying to run migrations on an Azure SQL database using the "mssql" client.

I've managed to correctly set up config to connect to the database but am getting following error when running ./ace migration:run

RequestError: select [name], [name] from [adonis_schema] order by [name] asc - Ambiguous column name 'name'.

@thetutlage
Copy link
Member

Can u share the migrations file?

@thetutlage thetutlage self-assigned this Dec 20, 2016
@alexblunck
Copy link
Author

Sorry for the late response. I just set up a fresh adonis project and used the auth:setup ace command create the default auth migration files. Running the migration works fine on sqlite & mysql databases but fails on mssql (azure).

The adonis_schema table is actually created, but the "RequestError" seems to indicate that there is a problem when trying to query the adonis_schema table before running the other migrations.

@alexblunck
Copy link
Author

Running following sql query manually works fine by the way:

select [name] from [adonis_schema] order by [name] asc

Is knex generating a wrong query?

@alexblunck
Copy link
Author

I did some digging and it looks like this "behavior is by design" in MSSQL (Source).

The error is caused by the ORDER BY part of the query requiring an unambiguous column reference.

Using an alias for the name column in the problem query seems to be the fix.

If you change the query in src/Migrations/Mixins/Migrate.js's _getMigratedFiles method to following the query runs successfully on MSSQL:

Migrate._getMigratedFiles = function () {
  return this.database.select('name as name_column').from(this.migrationsTable).orderBy('name_column').pluck('name')
}

The _getFilesTillBatch method needs the same change as well.

I've tried this with mysql & sqlite and it seems to work fine there as well. I'm note sure if this has any other implications, but this might be the simple fix.

@thetutlage
Copy link
Member

Thanks for finding that out. I will add MSSQL to the testing list and will this issue too.

@tanagorns
Copy link

it doesn't work for now
RequestError: select [name] as [name], [name] from [adonis_schema] order by [name] asc - Ambiguous column name 'name'.

@thetutlage
Copy link
Member

Are you trying it from Github? A release is yet to go on npm

@tanagorns
Copy link

yes, I have tried from github.

I have fixing code by

return this.database.select('name as aname').from(this.migrationsTable).orderBy('aname').pluck('name')

It's working

@KevinGruber
Copy link

i can confirm that the problem is that your [ as name ] fix in commit: fix(migrations): select column as {name}

is not working. The as name has to be something diffrent than name ;-) otherwise it is the same problem as before.

BR,
Kevin

@3dd13
Copy link

3dd13 commented Sep 1, 2017

The change actually broke the regression for Oracle

{ method: 'pluck',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [],
  __knexQueryUid: '54b49e9c-7924-44ca-9dd8-1a614b2e709d',
  sql: 'select "name" "name", "name" from "adonis_schema" order by "name" asc',
  pluck: 'name' }
Error: select "name" "name", "name" from "adonis_schema" order by "name" asc - ORA-00960: ambiguous column naming in select list

use as aname and order aname does fix it

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

5 participants