Reputation: 15
I did migrate from laravel with this migration file
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class MsCustomer extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('mscustomer', function(Blueprint $table)
{
$table->increments("custid");
$table->string("custname");
$table->string("password");
$table->string("email")->unique();
$table->integer("balance");
$table->string("role");
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('mscustomer');
}
}
and then it succeeded, a table with name 'mscustomer' was made in my database, and then I tried to use php artisan tinker by calling a model which is mscustomer.php, it contains
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class mscustomer extends Model {
}
then I get this error "Illuminate\Database\QueryException with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'twk.mscustomers' doesn't exist......"
what I can't understand it, I clearly created mscustomer, but why does it look for "twk.mscustomers" (with 's') behind, not twk.mscustomer. Is there any mistake did I do in this case?
please help me.
Note: sorry for the bad style of asking question, this is the very first time ever I ask a question here.
Upvotes: 1
Views: 771
Reputation: 152880
That's just how Laravel works. Eloquent will assume the plural of the model class name as table name. You can override this behavior by adding a property:
class mscustomer extends Model {
protected $table = 'mscustomer';
}
Besides that it's also pretty standard to use class names that start with a capital letter. In your case Mscustomer
(or maybe MsCustomer
) instead of mscustomer
Upvotes: 1