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

Foreign Key on String must raise if the size is not the same #134

Open
GohuHQ opened this issue Nov 5, 2019 · 2 comments
Open

Foreign Key on String must raise if the size is not the same #134

GohuHQ opened this issue Nov 5, 2019 · 2 comments
Assignees
Labels
bug
Milestone

Comments

@GohuHQ
Copy link
Contributor

@GohuHQ GohuHQ commented Nov 5, 2019

Error message:
Columns participating in a foreign key relationship must be defined with the same length and scale

Is it really needed to define the string size for those ?

name = String(size=256, primary_key=True)

A solution was to change the size to 64 instead of 256.

@GohuHQ

This comment has been minimized.

Copy link
Contributor Author

@GohuHQ GohuHQ commented Nov 12, 2019

sqlalchemy.exc.OperationalError: (pymssql.OperationalError) (1753, b"Column 'system_model.name' is not the same length or scale as referencing column 'io_mapping.model' in foreign key 'anyblok_fk_i_mapping__model'. Columns participating in a foreign key relationship must be defined with the same length and scale.DB-Lib error message 20018, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 20018, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\n")
[SQL: 
CREATE TABLE io_mapping (
        [key] VARCHAR(64) NOT NULL, 
        primary_key NVARCHAR(max) NOT NULL, 
        model VARCHAR(64) NOT NULL, 
        blokname VARCHAR(64) NULL, 
        CONSTRAINT anyblok_pk_io_mapping PRIMARY KEY ([key], model), 
        CONSTRAINT anyblok_fk_i_mapping__model FOREIGN KEY(model) REFERENCES system_model (name), 
        CONSTRAINT anyblok_fk_i_mapping__blokname FOREIGN KEY(blokname) REFERENCES system_blok (name)
)

@jssuzanne

This comment has been minimized.

Copy link
Member

@jssuzanne jssuzanne commented Nov 15, 2019

I think the better way is to check, in the case of foreign key with string, that the both string have the same size

@jssuzanne jssuzanne changed the title MsSQL: size=256 is not default for MsSQL Foreign Key on String must raise if the size is not the same Nov 15, 2019
@jssuzanne jssuzanne added the bug label Nov 15, 2019
@jssuzanne jssuzanne added this to the 1.0.0 milestone Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.