31 Replies
Im working on a self oriented project where i want to make a Vet Clinic Application,it shouldnt be too complicated and only needs to have models for owner,pet,and vaccine,and also an authentication system for the vet
I started work with the owner model and pretty much finished it by linking it to the database and getting it going
But as soon as i tried to add an area where a user has to enter their pets name and age i started getting database errors meaning i had to roll back
I am also working on this with a friend,he is doing the front end seperately and im just doing backend
You haven't really given us enough to help you. What errors are you getting in the DB? Code?
I had to roll back on my code because i couldnt get my database going,so perhaps you can help me go in the right direction with creating it
here is my owner model
pet model
vaccine model
owner controller
and my razor view
You're still not asking an actual question here
What specifically are you looking for help with
I need help editing my view
To create an area where i can add pets to my owner
I wanted to extend the default form
I added some code to the owners controller
and when i ran it i got database errors
You still haven't told us what database errors you were running into.
I dont have them saved
i think it was errors with name and surname
in my create action in create.cshtml
So try to add it again yourself and come back when you have something we can help you with.
Ok then
So i extended the view and controller
But now it doesnt save it to my database
Any errors?
nope
I tried updating my database trough nuget
i got some kind of error
Then set a breakpoint on the owner controller create method and make sure the
Owner
model you're parsing from the request is valid'FK_PetVaccine_Pet_PetsPetId' is not a constraint.
Could not drop constraint. See previous errors.
You don't update your database through nuget... nuget is a package manager for dependencies, migrations use the
dotnet
cli
Sounds like you have a bad migrationFailed executing DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
ALTER TABLE [PetVaccine] DROP CONSTRAINT [FK_PetVaccine_Pet_PetsPetId];
i tried going at it with the cli
but still the same error
I'd probably look at your table / schema and see if that constraint actually exists but has a different name. If not, you may need to delete that migration or manually update it so that it's valid.
how would i do that?
i think i found what it is mentioning
In that case I'd try updating your migration to have the correct FK name and see if that fixes anything
Or try to delete that migration first and create a fresh one to see if the problem persists
but now if i try to creae a new migration
it doesnt have any code at all
no altering no nothing
Probably due to your modelsnapshot file existing and being up to date with your code / the deleted migration
Is there a voicechat where you could help me in?
From here you can:
1) Update your model snapshot file by removing the stuff that was added with your most recent migration
2) Nuke your model snapshot and start from a fresh migration
So i can share to you
I'm not getting in VC
How do i nuke my model snapshot
actually
because i dont have any info in my db at all
can i just delete my db?
Delete the
SomethingSomethingSomethingModelSnapshot
file in the folder that has your migrations
yes, you can also delete your DB and start completely fresh
If you are doing that, you'd also want to delete everything in your Migrations
folderOk,i made a new database
but now again for some reason
since i added the new info to the controller
its not saving my data
So do what I suggested earlier and set a debug breakpoint on the controller method that's supposed to be creating owners and see what data it is getting passed