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

Column, parameter, or variable #1: Cannot specify a column width on data type text. #22424

Closed
himanshukodwani opened this issue Sep 6, 2020 · 6 comments
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported

Comments

@himanshukodwani
Copy link

I get this error when running Update-Migration.

///Error message Start

Applying migration '20200906170827_V1.0.0.1'.
Failed executing DbCommand (8ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [AccountGroups_DBSet] (
[GroupName] TEXT(50) NOT NULL,
[GroupParent] TEXT(50) NULL,
[BalanceSheetSide] TEXT(255) NULL,
[Description] TEXT(255) NULL,
[IsHidden] INTEGER NOT NULL,
[GroupEnd] TEXT(50) NULL,
[IsUnderBudgetControl] INTEGER NOT NULL,
[BudgetAmount] TEXT(64) NULL,
[IsUnderLocationControl] INTEGER NOT NULL,
[Location] TEXT(50) NULL,
[TxnID] TEXT(36) NOT NULL,
[SearchKey] TEXT(150) NULL,
[RecordVersion] INTEGER NOT NULL,
[CreatedBy] TEXT(50) NOT NULL,
[LastUpdatedBy] TEXT(50) NULL,
[CreatedOn] TEXT(48) NOT NULL,
[LastUpdatedOn] TEXT(48) NULL,
[Company] TEXT(100) NULL,
CONSTRAINT [PK_AccountGroups_DBSet] PRIMARY KEY ([GroupName])
);
Microsoft.Data.SqlClient.SqlException (0x80131904): Column, parameter, or variable #1: Cannot specify a column width on data type text.
at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) in ......More stack trace omitted

Error Number:2716,State:1,Class:16
Column, parameter, or variable #1: Cannot specify a column width on data type text.

///Error message End

But when I generate SQL Script using dbContext.Database.GenerateCreateScript(), the generated script is different and also works when creating database schema manually. Look at what SQL script saved in a file from the same migration looks like :

CREATE TABLE [AccountGroups_DBSet] (
[GroupName] nvarchar(50) NOT NULL,
[GroupParent] nvarchar(50) NULL,
[BalanceSheetSide] nvarchar(255) NULL,
[Description] nvarchar(255) NULL,
[IsHidden] bit NOT NULL,
[GroupEnd] nvarchar(50) NULL,
[IsUnderBudgetControl] bit NOT NULL,
[BudgetAmount] decimal(18,2) NULL,
[IsUnderLocationControl] bit NOT NULL,
[Location] nvarchar(50) NULL,
[TxnID] nvarchar(36) NOT NULL,
[SearchKey] nvarchar(150) NULL,
[RecordVersion] bigint NOT NULL,
[CreatedBy] nvarchar(50) NOT NULL,
[LastUpdatedBy] nvarchar(50) NULL,
[CreatedOn] datetime2 NOT NULL,
[LastUpdatedOn] datetime2 NULL,
[Company] nvarchar(100) NULL,
CONSTRAINT [PK_AccountGroups_DBSet] PRIMARY KEY ([GroupName])
);
GO

EF Core version:
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET Core 3.0)
Operating system:
IDE: (e.g. Visual Studio 2019 16.3)

@roji
Copy link
Member

roji commented Sep 7, 2020

The TEXT type has been deprecated in SQL Server and will be removed in a future version (see the docs), it also does not accept a size. AFAIK EF Core itself never maps to TEXT by default, are you explicitly configuring your column type?

Consider using nvarchar or nchar instead.

@ErikEJ
Copy link
Contributor

ErikEJ commented Sep 8, 2020

Looks like you are mixing SQLite and SQL Server migrations ??

@himanshukodwani
Copy link
Author

himanshukodwani commented Sep 8, 2020 via email

@himanshukodwani
Copy link
Author

himanshukodwani commented Sep 8, 2020 via email

@roji
Copy link
Member

roji commented Sep 8, 2020

You probably want to take a look at this doc page, about managing migrations in a multi-database scenario.

@roji roji added the closed-no-further-action The issue is closed and no further action is planned. label Sep 8, 2020
@himanshukodwani
Copy link
Author

himanshukodwani commented Sep 8, 2020 via email

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported
Projects
None yet
Development

No branches or pull requests

4 participants