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

Invalid SQL generated for migration if changing a column type [DNET707] #658

Closed
firebird-automations opened this issue Oct 20, 2016 · 3 comments

Comments

@firebird-automations
Copy link

Submitted by: Charles J Christie II (sonicbhoc)

I changed a column's type during development of a new application. Here's the line that was generated by migrations when I changed the data type on a property from int to long, neither of which were nullable:

ALTER TABLE "Booklets" ALTER COLUMN "File_Size" TYPE BIGINT NOT NULL
;

Apparently, it added the NOT NULL as part of the column definition, when the column was already NOT NULL. The problem is that Firebird doesn't allow changing from NULL to NOT NULL in the ALTER COLUMN clause, so the syntax was considered wrong and an exception was thrown.

(As an aside, the generated script from EF's Update-Database -Script command doesn't work when I try to read it into iSql using the IN command on the prompt, so I can't even change it and read it in that way. I'll have to apply the changes by hand until this is fixed.)

@firebird-automations
Copy link
Author

Commented by: Charles J Christie II (sonicbhoc)

I just realized that I never changed the null constraint at all in my code, just the type. But apparently the null constraint is considered a part of the type definition in EF, so it considered the type change to be from INT NOT NULL to BIGINT NOT NULL and created the statement accordingly.

Sorry for any confusion.

@firebird-automations
Copy link
Author

Modified by: Charles J Christie II (sonicbhoc)

description: I changed a column's type and null constraint during development of a new application. I found out later that Firebird doesn't support that through the ALTER TABLE ALTER COLUMN syntax, and that other options are available here: http://www.firebirdfaq.org/faq103/

Here's the line that was generated by migrations when I changed the data type on a property from Nullable<int> to long:

ALTER TABLE "Booklets" ALTER COLUMN "File_Size" TYPE BIGINT NOT NULL
;

Apparently, according to that page, all admin tools change the value on the system table. Maybe we should do that here too.

=>

I changed a column's type during development of a new application. Here's the line that was generated by migrations when I changed the data type on a property from int to long, neither of which were nullable:

ALTER TABLE "Booklets" ALTER COLUMN "File_Size" TYPE BIGINT NOT NULL
;

Apparently, it added the NOT NULL as part of the column definition, when the column was already NOT NULL. The problem is that Firebird doesn't allow changing from NULL to NOT NULL in the ALTER COLUMN clause, so the syntax was considered wrong and an exception was thrown.

(As an aside, the generated script from EF's Update-Database -Script command doesn't work when I try to read it into iSql using the IN command on the prompt, so I can't even change it and read it in that way. I'll have to apply the changes by hand until this is fixed.)

summary: Invalid SQL generated for migration if changing a column from null to not null => Invalid SQL generated for migration if changing a column type

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: Open [ 1 ] => Closed [ 6 ]

resolution: Incomplete [ 4 ]

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

No branches or pull requests

2 participants