Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SqlException: Invalid object name 'Movie'

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

like image 568
Ganeshkumar Miriyala Avatar asked May 08 '17 18:05

Ganeshkumar Miriyala


1 Answers

I had a similar error even though all the tables were properly created. It turned out that my connection string was wrong.

like image 72
mirosz Avatar answered Oct 02 '22 13:10

mirosz