question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception when using SQLite because of nvarchar(max)

See original GitHub issue

When using "UseSqlLite": true," the following exception is thrown.

System.AggregateException: 'One or more errors occurred. (SQLite Error 1: 'near "max": syntax error'.)'

Inner Exception:
SqliteException: SQLite Error 1: 'near "max": syntax error'.

This exception was originally thrown at this call stack:
    [External Code]
    BlazorBoilerplate.Storage.DatabaseInitializer.MigrateAsync() in DatabaseInitializer.cs
    [External Code]
    BlazorBoilerplate.Storage.DatabaseInitializer.SeedAsync() in DatabaseInitializer.cs

Many of the database models have .HasColumnType("nvarchar(max)"). But SQLite does not support varchar(max) according to https://github.com/dotnet/efcore/issues/7030. This is one of the limitations reported in the EF documentation.

There is an unresolved question on stackexchange regarding this topic. I did not manage to apply the suggested solution.

As a quick and dirty workaround one can replace every occurence with nvarchar(max) with nvarchar(2048).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
EmergentCyberneticscommented, Jun 25, 2021

@GioviQ I ran into the same issue when trying to use PostgreSQL, which is a server.

I’d like to be able to run this on PostgreSQL to make use of some other features we have in PostgreSQL. MS SQL has a hardcoded limit of requiring a server with 2GB or more of RAM, which is kind of a waste when PostgreSQL will easily run on a $5/month 1 core CPU and 1GB RAM server for our volume/load.

Being able to use SQLite is also nice for basic development. No need to setup a database server to get things running.

I’ll be working on getting PostgreSQL supported again over the next month. Do you have any suggesting on how to handle this nvarchar(max) problem? PostgreSQL equivalent data type is TEXT or VARCHAR for variable unlimited length.

I don’t see nvarchar(2048) as being a solution because 2048 characters isn’t always enough.

1reaction
GioviQcommented, Jan 3, 2021

A webapp should supoort thousands of concurrent users, with SQLite is not the case…

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQLite Error 1: near 'max' syntax error #7030
The issue here is varchar(max) is SqlServer specific type. The scaffolding should not add it as relational type which gets passed to migration ......
Read more >
EF Core SQLite in memory exception: SQLite Error 1: 'near ...
There is github issue saying: The issue here is varchar(max) is SqlServer specific type. The scaffolding should not add it as relational type ......
Read more >
Sqlite, nvarchar(max), Unit Testing #7130
My unit tests fails because I have nvarchar(max) in models and I am getting following error: Message: Microsoft.Data.Sqlite.
Read more >
EF Code First uses nvarchar(max) for all strings. Will this ...
And from a data integrity perspective, having nvarchar(max) will allow more bad data to be put in a field than specifying the limit...
Read more >
nchar and nvarchar (Transact-SQL) - SQL Server
No special error is provided when the table is created (beyond the usual warning that the maximum row size exceeds the allowed maximum...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found