At what level of this project should i be trying to install this migration? I want to install initial migrations to build my database form db context. Was having issues at first about update to ef migrations.. but it is now cleared. But i need to be installing
from correct folder in order to make it work! I keep getting build failed error! Cowboy2
Now that the model configuration is complete and provision for seed data has been made, you can create the actual migration. Execute the following command from the terminal:
dotnet ef migrations addCreateDatabase--output-dir
Data/Migrations
This creates a migration calledCreateDatabase. The files for the migration are generated in a newly created folder namedMigrationsin theDatafolder (as specified
by the value passed to theoutput-dirswitch): LearnRazorPages.com
But i have installed new migration dictionary as the previous instructions were not working!
And now their is the build failed error.'
I believe that it is saying that i am missing using the correct folder to begin my tooling."
Paul i tried to run my project in all configurations inside of visual studio. Core 1.1 to Core 3.1 I had no luck. Strange that this is a tutorial and it is recent but the project does not run like its supposed to!
Don't worry about migration for the moment. It seems that the problem is your project has compilation errors somewhere. You need to be able to build the project(s) before you can make any progress with things like migration.
Go to the 'Build' menu and choose 'Build Solution'. Do you get errors? What are they? There may be more than one error, only focus on the first one. What is the exact error message? Does it refer to a line of your code? Which line? Show us the line
of code with the error (and the method it is in if the method is not too long).
(If 'Build Solution' doesn't give errors then do a 'Build'=>'Clean Solution' and when it finishes try the 'Build Solution' again)
Paul, you were correct about the build. I found the issues and i was missing only some curly brackets in two of the classes. And now here are the most current errors since building the project. The project is saying the class is not present but i can definitely
see it there." Paul as per the instruction for the project, it says to add a using reference for Bakery Data. When i add this reference it throws an error unexpectedly. And then it becomes two using reference errors? Cowboy2
ps: see the "Adding and registering a Context" page 2. portion of the project tutorial. (add the using reference for Bakery Data)
When i add this reference it throws an error unexpectedly. And then it becomes two using reference errors?
Please post your detailed error message. Can you show me your complete dbcontext?
Best regards,
Sam
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Right-click on the red squiggly line. Choose "Quick actions and refactorings" The first option is probably "Using something". Select it. Does the red squiggly go away?
The error tells that you there is no namespace called Data within the namespace called Bakery. This will be because you do not have a code file which declares that namespace. You do have a file called BakeryContext.cs which would define the namespace if
it was compiled. Unfortunately, the file is in a sub-folder of the wwwroot folder which is only for static files (css, images and the like). Anything in this folder (or its children) is not compiled. Have a look at the properties of the file.
I suspect that your 'Data' folder should be at a higher level in the folder structure - definitely not within wwwroot. Typically it would be placed in the root of the project. I notice that the previous page of your tutorial says
To add one, create a folder named Data in the root of the project. Then add a C# class file to it named
BakeryContext.cs. Amend the content as follows:
So, the tutorial recommends the root of the project as a good place. I would agree with that advice.
Member
2 Points
8 Posts
Build failed error!
May 04, 2020 07:57 PM|Cowboy2|LINK
At what level of this project should i be trying to install this migration? I want to install initial migrations to build my database form db context. Was having issues at first about update to ef migrations.. but it is now cleared. But i need to be installing from correct folder in order to make it work! I keep getting build failed error! Cowboy2
https://ibb.co/yddSrf2
I keep getting build failed error! In command Line terminal.
https://ibb.co/p43pLw4
These are the instructions from the project:
Now that the model configuration is complete and provision for seed data has been made, you can create the actual migration. Execute the following command from the terminal:
dotnet ef migrations add CreateDatabase --output-dir Data/Migrations
This creates a migration called CreateDatabase. The files for the migration are generated in a newly created folder named Migrations in the Data folder (as specified by the value passed to the
output-dir
switch): LearnRazorPages.comBut i have installed new migration dictionary as the previous instructions were not working!
And now their is the build failed error.'
I believe that it is saying that i am missing using the correct folder to begin my tooling."
Participant
1620 Points
927 Posts
Re: Build failed error!
May 04, 2020 11:19 PM|PaulTheSmith|LINK
Does your project build? In all configurations? What errors do you get?
Member
2 Points
8 Posts
Re: Build failed error!
May 05, 2020 05:21 PM|Cowboy2|LINK
Paul i tried to run my project in all configurations inside of visual studio. Core 1.1 to Core 3.1 I had no luck. Strange that this is a tutorial and it is recent but the project does not run like its supposed to!
Steps: Create the Migration at bottom of Page."
https://www.learnrazorpages.com/razor-pages/tutorial/bakery/migration
LearnRazorPages.com/2020
Last updated: 29/05/2019 08:05:08
Participant
1620 Points
927 Posts
Re: Build failed error!
May 06, 2020 12:51 AM|PaulTheSmith|LINK
Don't worry about migration for the moment. It seems that the problem is your project has compilation errors somewhere. You need to be able to build the project(s) before you can make any progress with things like migration.
Go to the 'Build' menu and choose 'Build Solution'. Do you get errors? What are they? There may be more than one error, only focus on the first one. What is the exact error message? Does it refer to a line of your code? Which line? Show us the line of code with the error (and the method it is in if the method is not too long).
(If 'Build Solution' doesn't give errors then do a 'Build'=>'Clean Solution' and when it finishes try the 'Build Solution' again)
Member
2 Points
8 Posts
Re: Build failed error!
May 08, 2020 12:03 AM|Cowboy2|LINK
Paul, you were correct about the build. I found the issues and i was missing only some curly brackets in two of the classes. And now here are the most current errors since building the project. The project is saying the class is not present but i can definitely see it there." Paul as per the instruction for the project, it says to add a using reference for Bakery Data. When i add this reference it throws an error unexpectedly. And then it becomes two using reference errors? Cowboy2
ps: see the "Adding and registering a Context" page 2. portion of the project tutorial. (add the using reference for Bakery Data)
https://ibb.co/pdNfVY0
Contributor
3370 Points
1409 Posts
Re: Build failed error!
May 08, 2020 07:35 AM|samwu|LINK
Hi Cowboy2,
Is your dbcontext like below code?
If so, your Startup.cs should look like this.
If your Startup.cs is this.
Then you need to add below code in your DbContext.
Please post your detailed error message. Can you show me your complete dbcontext?
Best regards,
Sam
Participant
1620 Points
927 Posts
Re: Build failed error!
May 08, 2020 12:03 PM|PaulTheSmith|LINK
Right-click on the red squiggly line. Choose "Quick actions and refactorings" The first option is probably "Using something". Select it. Does the red squiggly go away?
Member
2 Points
8 Posts
Re: Build failed error!
May 08, 2020 03:41 PM|Cowboy2|LINK
Here is the screenshot of the errors! Cowboy
Member
2 Points
8 Posts
Re: Build failed error!
May 08, 2020 03:43 PM|Cowboy2|LINK
Paul, sorry but the quick action and refactorings does not fix errors!
Member
2 Points
8 Posts
Re: Build failed error!
May 08, 2020 03:48 PM|Cowboy2|LINK
Second Screenshot Startup.cs
https://ibb.co/WFR4fv3
Participant
1620 Points
927 Posts
Re: Build failed error!
May 09, 2020 12:44 PM|PaulTheSmith|LINK
The error tells that you there is no namespace called Data within the namespace called Bakery. This will be because you do not have a code file which declares that namespace. You do have a file called BakeryContext.cs which would define the namespace if it was compiled. Unfortunately, the file is in a sub-folder of the wwwroot folder which is only for static files (css, images and the like). Anything in this folder (or its children) is not compiled. Have a look at the properties of the file.
I suspect that your 'Data' folder should be at a higher level in the folder structure - definitely not within wwwroot. Typically it would be placed in the root of the project. I notice that the previous page of your tutorial says
To add one, create a folder named Data in the root of the project. Then add a C# class file to it named BakeryContext.cs. Amend the content as follows:
So, the tutorial recommends the root of the project as a good place. I would agree with that advice.