php - SQLSTATE [42S02]:未找到基表或视图:1146 表“laravel_abonamenty2.currencies”不存在
问题描述
我有这个错误
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel_abonamenty2.currencies' doesn't exist (SQL: select `id`, `currency`, `course` from `currencies`)
这是我的控制器,它会产生错误。我不知道 Laravel 为什么要搜索货币表。我的表和迁移称为 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');
}
}
解决方案
因为of的复数currency
是货币而不是货币。Laravel 自动检测snake case plural
模型名称的表名。文件
在您的模型中,您可以指定另一个表名,例如:
protected $table = 'currencys';
使用该 laravel 将搜索货币表。
推荐阅读
- eclipse-plugin - 如何从上下文菜单中删除 Eclipse Move 并重构主菜单
- mysql - 使表格数据可下载为 CSV 文件
- testng - 使用 maven-surefire 运行 testng.xml 时,由于依赖方法导致分叉进程显示错误
- javascript - 在 JavaScript 中从数组中删除元素
- youtube-api - Youtube API 直播:嵌入设置无效
- mysql - 为什么mysql在哪里提供带有字母数字值的结果?
- javascript - 屏幕阅读器不是在读取 aria-label 属性中的文本,而是在读取元素中的文本
- android - 有没有办法在点击按钮后隐藏容器/元素?
- power-automate - Flow Automate:如何从分页 API 返回中附加 JSON 数据对象
- javascript - ASP.NET View.aspx 在以零开头时转换字符串