Undefined table: 7 ERROR: relation "expenses" does not exist
When it says
relation "expenses" does not exist
It usually happens when your expenses table must have been dropped before migration:reset
rolled back CreateLocationsTable
.
Check the order of execution of your migrations.
As you were trying to reset, to fix it now, open your database, drop all tables manually and execute migrate
again.
Schema::table('expenses', function (Blueprint $table) { $table->foreign('location_id')->references('id')->on('locations')->onDelete('cascade'); });
change this to
Schema::alter('expenses', function (Blueprint $table) { $table->foreign('location_id')->references('id')->on('locations')->onDelete('cascade'); });
I had this error. I had to resolve it by adding the prefix of the database to my model. There is a way to change this in the database, and it is supposed to be changed. it's something, like $user, public. It's the schema profile. Mine is changed when I login, but for some reason the model is not binding to schema. So I had to specify it in the model. Instead of
protected $table = 'table_name';
I had to do
protected $table = 'schema_name.table_name';
Note: By schema_name or table_name, I'm not referring for you to put schema_ then the name. That is just so it's easier to read.The model is located in the model folder under the App/Models folder depending on which version of Laravel you using and how your Models are organized. If your model name is not the same as the table name, then you will need to put the protected $table. But if the schema is not there, then you will need to add that.
I do have this set in my DB_DATABASE_SECOND= in .env file. But it somehow still doesn't pick up the prefix.
But yeah. Pretty much I couldn't find the answer anywhere, but I