Php SQLSTATE[42S02]:未找到基表或视图:1146 table';货币';不';不存在

Php SQLSTATE[42S02]:未找到基表或视图:1146 table';货币';不';不存在,php,sql,laravel,orm,frameworks,Php,Sql,Laravel,Orm,Frameworks,我犯了这个错误 SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel_abonamenty2.currencies' doesn't exist (SQL: select `id`, `currency`, `course` from `currencies`) 这是我产生错误的控制器。我不知道拉威尔为什么要搜索货币表。我的表和迁移称为Currencys public function create() {

我犯了这个错误

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel_abonamenty2.currencies' doesn't exist (SQL: select `id`, `currency`, `course` from `currencies`)
这是我产生错误的控制器。我不知道拉威尔为什么要搜索货币表。我的表和迁移称为Currencys

public function create()
{
    $users = User::all('showname', 'id');
    $forms = Form::all('id', 'form');
    $currencys = Currency::all('id', 'currency', 'course');
    return view('invoices.create')->with('users', $users, 'forms', 'currencys');
}
这是我的货币模型:

namespace App;

use Illuminate\Database\Eloquent\Model;

class Currency extends Model
{
    protected $fillable = [
        'id', 'currency', 'course',
    ];

    public function invoice()
    {
        return $this->belongsTo('App\Invoice');
    }

    public function proform()
    {
        return $this->belongsTo('App\Proform');
    }
}
这是我的货币迁移

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class Currencys extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('currencys', function (Blueprint $table) {
            $table->increments('id');
            $table->string('currency')->nullable();
            $table->string('course')->nullable();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('currencys');
    }
}
按照惯例,将使用该类的复数名称“snake case” 作为表名,除非明确指定了其他名称。

在您的情况下,它将
货币
(型号名称)转换为复数
货币
。因此,如果需要自定义表名

您需要在模型中指定表的名称

货币模型

class Currency extends Model
{
  protected $table="currency";
...
}

因为
货币
的复数形式是货币,而不是货币。Laravel自动检测模型的
snake-case复数形式的表名

在模型中,可以指定另一个表名,如:

protected $table = 'currencys';

有了这个,laravel将搜索currencys表