小编Leo*_*iro的帖子

Laravel本地主机工作,但是Heroku给出了500错误

我正在一个需要将某些数据从excel转换为数据库的项目中。这在使用laravel的本地主机上运行良好,但是当转到heroku时,它给了我500内部服务器错误。

我在heroku中搜索可能指向的内容,然后发现heroku的数据库中有两个从请求中插入的值。因此,这意味着代码循环了两次,但随后发生了错误。

我试图在代码中找到错误4个小时,但没有发现发生了什么...

这是代码:

public function insertFromExcel(){

        $excel = new \Maatwebsite\Excel\Facades\Excel();

        $data = $excel::load('../../../excel_files/relacao_5.xls', function ($reader) {

        })->get();

        foreach ($data as $row) {


            //-----------------------------------------Verifica Setor-------------------------------------

            if(isset($row['nome_setor'])){
                $setor_id = DB::table('setor')->where('nome', '=', $row['nome_setor'])->pluck('id');

                if ($setor_id == null) {
                    $setor_id = DB::table('setor')->insertGetId([
                        'nome' => $row['nome_setor']
                    ]);
                }
            }
            else{
                $setor_id = null;
            }

            //-----------------------------------------Verifica Funcionario--------------------------------

            $funcionario_id = DB::table('funcionario')->where('matricula', '=', $row['codfun'])->pluck('id');



            if ($funcionario_id === null) {
                $funcionario_id = DB::table('funcionario')->insertGetId([
                    'nome' => $row['nome_func'],
                    'matricula' => $row['codfun'],
                    'pis_pasep' => $row['pis_pasep'],
                    'data_admisao' => $row['admissao'],
                    'setor_id' => $setor_id …
Run Code Online (Sandbox Code Playgroud)

php postgresql heroku laravel

6
推荐指数
4
解决办法
6457
查看次数

Laravel 5.1 - 一般错误:1005无法创建表(mysql)

我正在使用laravel来迁移一些数据,但我在下面有这样的消息:

[Illuminate\Database\QueryException]                                                                                                                                                                
  SQLSTATE[HY000]: General error: 1005 Can't create table 'heinz.#sql-1e83_8' (errno: 150) (SQL: alter table `funcionarios` add constraint funcionarios_supervisor_id_foreign foreign key (`supervis  
  or_id`) references `funcionarios` (`id`))  
Run Code Online (Sandbox Code Playgroud)

我尝试了很多东西,但没有奏效.

这是迁移文件的代码.(相关部分).

Schema::create('funcionarios', function (Blueprint $table) {

//            $table->engine = 'InnoDB';

            $table->increments('id');
            $table->string('nome', 60);
            $table->integer('matricula')->unsigned()->unique();
            $table->bigInteger('pis_pasep')->unsigned()->nullable();
            $table->date('data_admissao')->nullable();
            $table->date('data_demissao')->nullable()->default(null);
            $table->date('data_nascimento')->nullable();
            $table->string('apelido', 20)->nullable();
            $table->integer('supervisor_id')->nullable();
            $table->integer('coordenador_id')->nullable();
            $table->integer('gerente_id')->nullable();
            $table->integer('diretor_id')->nullable();
            $table->integer('sexo_id')->nullable();
            $table->integer('setor_id')->nullable();
            $table->integer('cargo_id');
            $table->integer('turno_id')->nullable();
            $table->timestamps();
        });

        Schema::table('funcionarios', function($table){

            $table->foreign('supervisor_id')->references('id')->on('funcionarios');
            $table->foreign('coordenador_id')->references('id')->on('funcionarios');
            $table->foreign('gerente_id')->references('id')->on('funcionarios');
            $table->foreign('diretor_id')->references('id')->on('funcionarios');
            $table->foreign('sexo_id')->references('id')->on('sexos');
            $table->foreign('setor_id')->references('id')->on('setores');
            $table->foreign('cargo_id')->references('id')->on('cargos');
            $table->foreign('turno_id')->references('id')->on('turnos');

        });
Run Code Online (Sandbox Code Playgroud)

php mysql laravel laravel-5.1

1
推荐指数
1
解决办法
4909
查看次数

标签 统计

laravel ×2

php ×2

heroku ×1

laravel-5.1 ×1

mysql ×1

postgresql ×1