ASP.NET Identity Login Error
When trying to sign in using SignInManager, I get a SqlException: Invalid column name 'UserId1'.
Why is there an extra user column being added to the query? My extended identity classes are listed below.
114 Replies
Have you created and ran the migrations?
yes i have, my db matches that
i mentioned it happening with PasswordSignInAsync() but honestly it keeps happening with almost any method related to those tables
oops turns out i hadnt
:when:
how do i get it to work tho
like the migration error
You tell me.
fuck
enchantment table errors
one moment
omg it wont let me copy the text
is that any better
Well it's readable, but none of those are errors
wait so why is there an X
Is that all the text?
Also... Ef power tools? Wtf is that
GitHub
GitHub - ErikEJ/EFCorePowerTools: Entity Framework Core Power Tools...
Entity Framework Core Power Tools - reverse engineering, migrations and model visualization in Visual Studio & CLI - ErikEJ/EFCorePowerTools
everyone uses it
theres so much i cant fit it on my screen and the window isnt resizeable lmao
the migration tool is in preview still ig so i should probably do it via command line?
thats distinctly not true, as I've never heard of it before :p
dotnet ef
is all you needok
also, uhhh
EF7
?
why does it say EF7 in several places
what .NET version are you using on this project? And what packagereference version is your EF package?.net 8
also that repo isnt mine
i just wanted to give u more info on the tool i was using
so ignore the ef7 thing
Ah right, its the preview thingy
but yea im using .net8 with razor pages
Microsoft.Data.SqlClient.SqlException (0x80131904): There is already an object named 'TestTypes' in the database.
i tried doing it via cli but it throws an error on my first table saying it already exists?
sounds like your migrations are out of sync with your database
if there's nothing valuable in the DB just delete it and recreate it
ok so i reran the migration command but before i could, it wanted me to update to .net8.0.2, so i did, and now i got this in the console and my app wont even open in the browser now lmfaoo
Why are you uploading text? Just paste it.
i did
it auto did that
If it's too long, use pastebin
Opening txt files on a phone is not a fun experience
because of the cahracter size
Pastebin
[10:55:14 DBG] An 'IServiceProvider' was created for internal use b...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
BlazeBin - bhtelnoscqgm
A tool for sharing your source code with the world!
lol sorry about that
its not your fault, its just that its too long so discord automatically converts it to a file
yea i hate it when it does that XD
I blame Pobiega :madcar:
Wtf
Ok I'm at a bathhouse so Leo, congratulations I appoint you in charge of this
ok anyway so clearly my models are fucked if theres all these shadow properties right
well I dont know Identity so lets see
@Lamp where u deploying these to? local db or what
sql server
and did u dump the db before running migrations again given what macle said, if u dont have anything of value in it
Those errors are from generating the migration, no?
It sure look like it
ahh, it is kinda valuable unfortunately
Are you adding identity to an existing database?
and u should have scaffolded the db models
not create a new one on top
ok so long story short, i got hired recently, boss is in the hospital (2 person team) so i cant ask him, he just handed me a "copy" of the db that i can use locally along with the app he was working on
afaik we're using the individual accounts razor pages template just with a bunch of our own stuff built on top
and i believe the db started out with identity, like all the AspNetUsers, AspNetRoles, etc are there
are you sure the version of the code you're using matches what is compatible with the DB you were given?
that sounds more like you were given 2 things that didn't work together to begin with
honestly, no im not entirely sure, however i have used the efcore power tools reverse engineer feature to generate the models and such for me... but when i do that, none of the identity code comes in, i have to manually add that every time
ig so far its been "db-first" design?
what version of identity/ASP.NET generated the database?
i don't think db-first is going to work nicely here because the models it would be generating are built into the identity library
now that you mention it, that makes a lot of sense
why are you trying to scaffold an identity database that another application generated anyway?
its a relatively new project so its .net8 but where would i check the identity version? i assume its the newest?
you'd check the code of the application that created this db
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.2" />
yea its the latest one i believe
is the project you're working on now the same one that "owns" this database or are you trying to pull in data from another application?
yes, the project im working on is the same one that owns the db. im like 99% sure of that
then you shouldn't be scaffolding anything
or making any of your own migrations unless you change the models yourself
wait, why?
because the application will already have the migrations it used to get the database to the state it's in now
sooo... about that.
there are none
okay, go to the database and look at the __EFMigrationsHistory table
its empty and didnt exist (i dont remember seeing it) until i tried to run my own migration
does the application call
.EnsureCreated()
anywhere in its startup code or something?no
so how did the database come to exist in the first place?
I assume my boss made it somehow
yes, the options are either migrations or calling EnsureCreated
it should 100% be migrations if you ever planned to change anything about the database
if you have no migrations, this was broken before you ever touched it
wait is it possible he made it manually then just used the reverse engineer tool to generate the models
then manually added the identity dbcontext stuff
that would be very dumb and unlikely, but technically maybe
hmm
is there any way for me to fix it?
that would still make no sense thou he made the app right?
yes
assuming the code you have has the same model that was used to set up the DB, you can create an initial migration and manually record it in the __EFMigrationsHistory table
so he should have the models right
so EF won't try to apply it and future migrations will build on it
or find someone who can answer why there are no migrations in the codebase
ok i did some searching and in the repo we have, his first commit had migrations, however he deleted the folder in the next commit
and those would be pretty out of date for how the tables look now
so i should just do this?
they should never have been deleted, they're as important as the rest of the code in the project
yeah if they're just gone you should create a new "initial" migration and fake it being applied
ok i just did the initial commit
add a row that looks something like this
but with your actual migration name
i was just going to ask that, lol, thank you!
assuming the models match the DB then you'll be good, if not you're kind of stuck
the name of the file is 20240307155516_InitialCreate.cs, do i need to include the "create" portion?
yeah
just take the .cs off
good?
yeah, i don't know what it uses the productversion for so you may have to make that a real EF version
but you can try it
how would i test that it works?
this doesn't do anything on its own, it just stops future migrations from trying to create things that already exist
ok gotcha
you've basically synced up what the migration tool thinks the DB currently looks like with what it actually currently looks like
(assuming your models matched already)
shit new issue, when i installed the ef cli tools, i had to update to .net 8.0.2, and now the app opens in the browser but cant find any of my pages
😠i didnt even touch anything
i updated from 8.0.1 to 8.0.2
do you have important work on your working branch? if not i'd just roll back to whatever you were initially given, do the migration thing, then go from there
sadly yes
i 100% fucked up
either way, i'd start fresh and make that work, then move your changes on top of that
check out a fresh copy somewhere else to try fixing
a fresh copy of the repo?
i assume?
right
then theoretically you can apply your existing commits on it once you've fixed it, minus any scaffolding jank
or just copy/paste the code
so with that, there really hasnt been a point where the identity stuff worked
i mean maybe when the app was created
as in the deployed version doesn't work either?
this app isnt deployed yet, we're trying to get it ready for production soon
for queries, most things work, but if its related to identity, it tends to break
that's my main issue i've noticed
so just for fun, use your migration to create a brand new DB and see if things work that way
assuming your application can bootstrap itself from a fresh database, which isn't a guarantee at this point :KEKW:
if nothing is in prod then the existing data probably isn't that important
fair
and that will at least help you determine whether identity is really broken or someone just messed up the database at some point and never fixed it
which is likely if they thought deleting migrations was a good idea
wait wdym
how would i do that
i mean if the application code depends on data already being in the database then it will probably not work if the database is brand new
only one way to find out, create a db, apply the migration, and see if it works
ohh i see
before i do that, i need my app to work tho
this is part of making your app work
cause it wont open now
that's why i'm saying start over and re-apply your code but without the stuff that broke it
the only thing that i changed from when it was running to when it broke was updating to .net8.0.2
(also fwiw you can install specific versions of tools and not update your whole project)
then undo that
so i didnt update the project i literally installed it from https://dotnet.microsoft.com/en-us/download/dotnet/8.0
*installed .net 8.0.2
apologies i had a meeting
CS9057 The analyzer assembly 'C:\Program Files\dotnet\sdk\8.0.201\Sdks\Microsoft.NET.Sdk.Razor\source-generators\Microsoft.CodeAnalysis.Razor.Compiler.SourceGenerators.dll' references version '4.9.0.0' of the compiler, which is newer than the currently running version '4.8.0.0'.
i noticed this in my error list, but just listed as a warning could that be it? i did this but i just cant test it yet cause the app wont open
i noticed this in my error list, but just listed as a warning could that be it? i did this but i just cant test it yet cause the app wont open
then install the .NET version that worked
Ok, literally restarted my pc and its working again lmfao
Love that