SqlException: Invalid object name 'Movie'

asp.net-core asp.net-core-mvc c# entity-framework-core sqlite

Question

I am trying to follow the tutorial from the link below to create an app that shows a list of movies from a database with crud functionality, but I am trying to add a user login. https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/

I have been trying to figure out how to add and update the migrations for the Movie database. I am able to do it when I follow the tutorial without the user login, but once I add the user login, there seems to be an issue that I am not catching.

After I create the model class, I am trying to apply the following steps for the migration

  1. Goto the command line and access the folder with the project in it
  2. apply the following commands
    • dotnet restore
    • dotnet ef migrations add --context MvcMovie2Context (When I run this command, I get (Missing required argument ''.) error)
    • dotnet ef database update --context MvcMovie2Context (This command seems to be working for some reason)

When I run the app and click on the movie link, I get the following error

SqlException: Invalid object name 'Movie'.
System.Data.SqlClient.SqlCommand+<>c.<ExecuteDbDataReaderAsync>b__107_0(Task<SqlDataReader> result)

I have looked through my Model, View and Controller classes to check if I made a typo or a syntax error that would cause the object name ‘Movie’ to be invalid, so I think it means that my Movie database was not created.

I have restarted the project multiple times following the tutorial

I have attached screenshots of the command line errors and browser error. I would greatly appreciate if anyone has any hints or suggestions that they could provide me. Thanks!

error messages

1
2
2/14/2018 6:20:28 PM

Popular Answer

Since the error is SqlException: Invalid object name 'Movie', that means the table named 'Movie' has not created or the Database you are referring has not created.

To see if the Database or table 'Movie' has created, open SQL Server Object Explorer and check the Database name is the same as in appsettings.json. If the Database or table has not created, you may need a migration.

To migrate, open Tools-> NuGet Package Manager-> Package Manager Console and hit the following commands:

  1. Add-Migration MigrationName
  2. Update-Database

Then check SQL Server Object Explorer again or build and run your project.

3
11/4/2017 9:00:08 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow