-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Knex tries to drop not null
during alter table migration
#4401
Comments
That is how it was designed to work http://knexjs.org/#Schema-alter
Though looks like it doesn't work for changing primary key column type (it actually only works for some really basic cases). I suppose that it could recognize when primary column in PG is modified and not try to drop null constraint in that case. That method actually works only for really limited simple use cases. |
I also noticed that if you provide the constraint, it first deletes it and then applies it again. Tuat is an easier way to do it I guess, but it doesn't work in cases like that. I think it might be doable to check if there is still a not null able constraint and in this case not generate drop not null at all. Or make it explicit (which would be a breaking change) |
Since |
It comes from the design that knex actually doesn't know anything about the schema so it doesn't know if the constraint was there in the first place. Having schema system completely out from knex core repo would be a lot better for the project to allow more relaxed feature development on that side. I wont like to have really sophisticated schema functionality on core repository, because It will easily require 10x more code to implement well than the knex core query builder + execution abstracting parts. |
I think simplifying it would be better actually: That would make the schema alter completely deterministic, and also not require any schema reading. |
@yhaskell PR for this functionality, as long as it is not a breaking change, would be most welcome! |
That would be a breaking change and would induce need for all other type of additional .dropXXX() methods, which can already be used separately without In which case drop + recreate is a problem? Giving option to |
@elhigu drop + recreate fails on all alters of a primary key column |
@yhaskell Ah right. Yeah then giving options to |
Released in 1.0.2 |
Environment
Knex version: 0.95.3
Database + version: PostgreSQL 12.5
OS: MacOS 11
Bug
I am trying to write a migration that changes a type of a column to the other type:
Migration #1 passes correctly and is not relevant in any way except for providing example structure.
Migration #2 fails (for both primary and alternative version) with the following message:
I added a log for queries in the
compiler.js
file and it outputs the following:where as I expect the one and only query:
The text was updated successfully, but these errors were encountered: