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

Migrating in SQLITE: dropColumn throws error #3473

Closed
wsjwa opened this issue Oct 9, 2019 · 6 comments · Fixed by #3476
Closed

Migrating in SQLITE: dropColumn throws error #3473

wsjwa opened this issue Oct 9, 2019 · 6 comments · Fixed by #3476

Comments

@wsjwa
Copy link

wsjwa commented Oct 9, 2019

sqllite Version:
"sqlite3": "4.0.2",

If you have a migration with dropColumn, you'll get the error:
TypeError: Cannot read property '1' of null

Because in knex\lib\dialects\sqlite3\schema\ddl.js:
_doReplace() is being called and the Regex searches for "CREATE TABLE..."

Migration:
builder.schema.alterTable('USER', table => { table.dropColumn('DESCRIPTION'); });

Is there a workaround or alternative to dropping columns/changing the column type?

dropColumns() throws the same error btw

@wsjwa
Copy link
Author

wsjwa commented Oct 10, 2019

Knex Version is: "0.17.3"

@lorefnon
Copy link
Collaborator

Can you please share the result of the following (from sqlite shell):

select name, sql from sqlite_master where type = "table" and name = "USER"

@wsjwa
Copy link
Author

wsjwa commented Oct 11, 2019

Result for XC_USER:
sql: CREATE TABLE XC_USER(ID TEXT NOT NULL PRIMARY KEY, XC_MANDANTEN_ID TEXT NOT NULL, LANDINGPAGE TEXT NOT NULL, NAME TEXT NOT NULL, DESCRIPTION TEXT NOT NULL, EMAIL TEXT NOT NULL, PASSWORD TEXT NOT NULL, CREATED_AT TEXT NOT NULL, CREATED_BY TEXT NOT NULL, LAST_LOGIN TEXT NOT NULL, LANGUAGE TEXT NOT NULL, ACTIVE INTEGER NOT NULL, ADMINISTRATOR INTEGER NOT NULL, GROUP_ADMIN INTEGER NOT NULL)

name: XC_USER

@wsjwa
Copy link
Author

wsjwa commented Oct 11, 2019

Should the method even be called at all? Because i'm trying to drop a column and not create a table

@ricardograca
Copy link
Member

ricardograca commented Oct 11, 2019

SQLite doesn't support renaming or dropping columns with a single query: https://www.sqlite.org/lang_altertable.html

lorefnon added a commit that referenced this issue Oct 11, 2019
1. Fix regex match failure when table has not been created through knex's createTable (Closes #3473)
2. Handle all quote variants supported by SQLite.
3. Fix incorrect handling of foreign keys & constraints
@kibertoad
Copy link
Collaborator

Released in 0.20.0

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

Successfully merging a pull request may close this issue.

4 participants