Entity Framework - Row size greater than allowable maximum row size of 8060

后端 未结 1 1752
-上瘾入骨i
-上瘾入骨i 2020-12-06 08:04

I have an entity with a binary datatype and a corresponding varbinary(max) column in SQL Server. EF creates this:

CREATE TABLE [dbo].[Attachment         


        
相关标签:
1条回答
  • 2020-12-06 08:17

    The only way I can see you getting this error with that table definition is if you have previously had a large fixed width column that has since been dropped.

    CREATE TABLE [dbo].[Attachments] (
        [Id] int IDENTITY(1,1) NOT NULL,
        [FileName] nvarchar(255) NOT NULL,
        [Attachment] varbinary(max) NOT NULL,
        Filler char(8000),
        Filler2 char(49)
    );
    
    ALTER TABLE  [dbo].[Attachments] DROP COLUMN Filler,Filler2
    
    INSERT INTO [dbo].[Attachments]
    ([FileName],[Attachment])
    VALUES
    ('Foo',0x010203)
    

    Which Gives

    Msg 511, Level 16, State 1, Line 12 Cannot create a row of size 8075 which is greater than the allowable maximum row size of 8060.

    If this is the case then try rebuilding the table

    ALTER TABLE [dbo].[Attachments] REBUILD 
    
    0 讨论(0)
提交回复
热议问题