Exception when using SQLite because of nvarchar(max)
See original GitHub issueWhen 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:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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 isTEXT
orVARCHAR
forvariable unlimited length
.I don’t see
nvarchar(2048)
as being a solution because 2048 characters isn’t always enough.A webapp should supoort thousands of concurrent users, with SQLite is not the case…