Incorrect syntax near the keyword 'NOT'. error during ef database update
I've been following a Asp.net core web api tutorial https://www.youtube.com/watch?v=SIQhe-yt3mA&t=436s and I keep getting this error when trying to do the dotnet ef database update command. I've tried lots of things, but I'm a bit stumped here
Error Number:156,State:1,Class:15
Incorrect syntax near the keyword 'NOT'.
Teddy Smith
YouTube
ASP.NET Core Web API .NET 8 2024 - 3. Entity Framework
ASP.NET Core Web API .NET 8 2024 - 3. Entity Framework
Github: https://github.com/teddysmithdev/FinShark
SQL Server Connection String Template (WINDOWS):
"Data Source={PCNAME}\SQLEXPRESS;Initial Catalog={DATABASENAME};Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSub...
"Data Source={PCNAME}\SQLEXPRESS;Initial Catalog={DATABASENAME};Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSub...
126 Replies
you'll need to show your code
I did on my first post :(
it was on the code review
what particular files?
just upload it all to github tbh, much easier for everyone
okay
what database engine are you using? looks like mssql based on what connector its using
but what version?
ssms
your error is that the SQL server responded that the query is invalid, which is weird since ... "NOT NULL" in a create table is definately valid
SSMS isnt a database, its a database client
AHHHH
sqlexpress
right
um
hear me out
try running that query manually in SSMS, just to see if it works?
Im gonna need to download the github thing
okay
can do it in a transaction, if you dont want it saved
you dont need to download the github thing - VS has built in git
and you dont need their client
in fact, I think their client is trash
yea the guy was using vscode
im trying not to kms rn
vscode also has built in git š
WHERE IS IT
I founmd ioit
404
can u see a private one
orr...
no, thats what private means
:p
im so sorry man
this site is too godamn big
ignore git for now then, run the query
it's the nots maybe actually
oh wait
I see the error
decimal (18,2
omg
.. did you write the query yourself?
no
I find it unlikely that EF would generate an invalid query
model
idk
look at your typenames wtf
>_>
LMFAOOO
no
it wasn't doing it itself
i was having to do it
I was going to
i promise
repeat after me: I will use
IEntityTypeConfiguration<T>
in the future, not the silly attributesWHAT IN THE FUCJ
what
configuring your models with
[Bla]
is not recommendedwoah
only a very small subset of configuration can be done with attributes
and also lead to shit like this
yea it was too easy :\
explicit IEntityTypeConfigurations are better.
anyways, easy fix - fix your attributes, remove the migration and snapshot, generate a new migration
bro I might cry
im not even on a chatbot
why
... what
idk
why are people alergic to the documentation
god
I looked
it was words and more documentation
top 2 results
yes
I have it open
š
yea
I was like
where is that exactly
like
in the model?
no
a separate class
this class configures EF for
Blog
so can i put this in data
or is this a model thing
its an EF thing. it should live near your context.
my current files
if your Context is at
Project.Data
, I'd put it in Project.Data.Configurations
okay
then do
modelBuilder.ApplyConfigurationsFromAssembly(typeof(BlogEntityTypeConfiguration).Assembly);
in your contexts OnModelConfiguring
to load all the configs
you dont need the attribute to associate the model with the config
bit of a rant thou, why are young coders so against reading docslmfdaoooo
idk
it's more because it's all abstract things
sure, documentation is long and wordy, but thats cause its not a direct answer to a single question, its describing an entire section or feature
and I'm like sitting here rn thinking
god I hate following tutorials
okay I name this FInshark Configurations
orsomething
like
FinsharkConfigurations
and then
or stock
generally you make one of these for each model
yea
stockentitytypeconfiguration
okay
so the config for
Stock
would be internal class StockConfiguration : IEntityTypeConfigration<Stock>
eh, maybe make it public, doesnt really matterwhy does my vscode hate me
it says is a reference missing
HELP ME VSCODE HELP ME THEN
GIVE ME THE REFERENCE PAL
š
okay
I was being an asshole
it worked
except the url thing
uuh
why is it nested
dude
okay
cursed indentation :p
but sure
is the url thing fine
or am i dead
do you have a property called Uri?
not that I've been using this far
in my minmdddd
I can go check
nope
based on the model you showed before, you'd configure the properties for Profit and Purchase
since you had changed their types
can I get rid of them :)))
wdym?
if you dont need to configure them at all, then why have we just wasted 15 min setting up entity configuration?
eh
ykw
lets keep going
but if the numbers truly were the issue
omfg
...
it's for a tutorial man
the numbers were not the issue
oh
see
the issue was THE MISSING PARENTHESIS
I can't fix that
decimal(18,2
is NOT THE SAME as decimal(18,2)
I didn't make it
"I cant fix that"
sure you can
is fixing it
you have the file ON YOUR COMPUTER
>_>
its literally two characters
jesusadxgfhujbsanojfgas
lmfaooo
well
long route works
idrk
how would I fix that tho
what are you fucking on about
LOOK AT YOUR MODEL
hm
its not
LFMAOOO
blind
legally blind
illegally blind?
maybe.
hm.
touche
why
why did you walk me down that long ass road
just to stop me there
we were about to embark on like one piece or smth
I pointed it out 30 min ago
hey
but you should not do EF configuration using
DataAnnotation
attributesthis is quite entertaining, keep it up guys
this is why I fucking hate this discord omg š
thats why I said use IETC
lol?
im sorry
I love you
thank you for your help
i was laughing my ass off
explain this tho
so
configurations
they are like optional right
in a way
my thing will run with the ones from ms unless I change whatever for whatever I need
if you dont use configurations in any way, you get the defaults
sometimes thats fine
sometimes you need to configure stuff
yeaa :3
there are 3 ways to configure an EF entity
1. data annotations - the attributes you are currently using
2. inside the context
3. with dedicated entity type configration classes
3 is the recommended approach
preach
1 is what all shitty youtube tutorials do, because their examples are trivial
and would you believe it, in a trivial example, you can often get away with it
but for configuring a Many-to-Many relationship, or a two way type conversion, or owned entities, you need to use 2 or 3, and 3 is just "cleaner" since its each model for itself
instead of all of them in one blob
um
so
question
I'm quivering in anticipation
documentation may serve it's purpose for once in my life tbh
GitHub
GitHub - Yeeeef/WebApi
Contribute to Yeeeef/WebApi development by creating an account on GitHub.
got it
um
okay it's building
cool
thanks for the help