php – Laravel播种错误 – 错误的表名

当我尝试为数据库播种时,Laravel会抛出此错误.

我的表是INSTIT_school而不是institution_schools,Laravel在错误中报告了什么.

 [Illuminate\Database\QueryException]
 sqlSTATE[42S02]: Base table or view not found: 1146 Table 'eesdatabase.inst
 itution_schools' doesn't exist (sql: insert into `institution_schools` (`sc
 hool_id`,`instituion_id`,`energy_id`,`year`,`updated_at`,`created_at`)
  values (38,1,2005,2014-07-04 19:38:41,2014-07-04 19:38:41))

我尝试删除数据库,然后再次迁移和播种.
我尝试用“PHP artisan:cache clear”重置Laravel缓存

有谁知道如何解决这一问题?
谢谢

PHP    
class InstitutionSchool extends Eloquent {


    protected $table = "institution_school";        
    protected $guarded = array('id');

    public function school() {
        return $this -> belongsTo('School');
    }

    public function institutio() {
        return $this -> belongsTo('Institution');
    }

    public function energy() {
        return $this -> belongsTo('Energy');
    }    
}
?>

PHP
class InstitutionSchoolTableSeeder extends DatabaseSeeder {
    public function run() {
        DB::table('institution_school') -> delete();

        $faker = $this -> getFaker();
        $schools = School::all();
        $institutions = Institution::all();
        $energies = Energy::all();

        foreach ($schools as $school) {
            for ($i = 0; $i < rand(1,5); $i++) {
                $year = $faker -> randomNumber(2000,2015);

                InstitutionSchool::create(array(
                'school_id' => $school -> id,'instituion_id' => 1,'energy_id' => 1,'year' => $year));
            }

        }
    }

}
?>

PHP    
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateInstitutionSchoolTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('institution_school',function(Blueprint $table)
        {
            $table->increments('id');
            $table->integer('institution_id')->unsigned();
            $table->integer('school_id')->unsigned();
            $table->string('year');
            $table->string('other_source_name')->nullable();

            $table->integer('energy_id')->unsigned()->nullable();

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('institution_school',function(Blueprint $table)
        {
            Schema::drop('institution_school');
        });
    }    
}
最佳答案
尝试在模型中明确定义表名.它可能会奏效.但它当然不是一个完整的解决方案,只是让它成功的黑客攻击:D

protected $table = "institution_school";

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


mysql外键怎么用?Mysql数据库外键的使用介绍(图文+视频)
mysql怎么创建视图?(图文+视频)
怎么修改Mysql数据表中的视图
phpMyadmin导出备份数据库文件的步骤详解(附视频)
怎么给Mysql数据表添加外键?(图文+视频)
phpMyadmin导入数据库sql文件的方法详解(附视频)
如何查询mysql数据表中的视图
Mysql怎么删除外键?(图文+视频)
mysql数据表视图是什么意思?有哪些用处?(图文+视频)
mysql数据库怎么创建外键?(图文+视频)
Navicat怎样导入导出sql文件?(图文步骤+视频教程)
phpMyAdmin最新下载安装教程(附视频)
怎么使用phpmyadmin对数据库、数据表进行增删改查等操作?(图文+视频)
Mysql外键是什么?有哪些用处?(图文+视频)
怎么使用Mysql数据表中的蠕虫复制
Mysql事务提交及事务回滚是什么意思
怎么向Mysql视图中增加新数据
not exists用法
怎么删除mysql表中数据
Mysql数据表中手动事务的回滚点是什么