0
I have a project in Laravel that after I formatted the computer I can no longer open it. The following steps have been performed:
- Installation of XAMPP and change the default path to the project folder.
- Installation of Composer and subsequently update thereof.
- Creation of the project database on Mysql.
- When rotating the command PHP
artisan migrate
andartisan serve
appears the following error:
The file . env is configured this way. This key was there the same way before the machine was formatted. Running php Artisan key:generate gives error and cannot generate new key.
Code
APP_ENV=local
APP_NAME=SGP
APP_KEY=base64:eEtD6lSEsQGE/aDDVHgVHXKLpmaj1XzhMTtiFhOukqQ=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://sgp.patrimonio
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=sgpmehos_bd
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
The Migration that is showing error is 2017_10_22_134724_create_permissions_table.php and the codes inserted in it are:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePermissionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('permissions', function (Blueprint $table) {
$table->increments('id');
$table->string('nome', 50);
$table->string('label', 200);
$table->timestamps();
});
Schema::create('permission_role', function (Blueprint $table) {
$table->increments('id');
$table->integer('permission_id')->unsigned();
$table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');
$table->integer('role_id')->unsigned();
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('permissions');
Schema::dropIfExists('permission_role');
}
}
Model: Permission.php
<?php
namespace App\Models\Acesso;
use Illuminate\Database\Eloquent\Model;
class Permission extends Model
{
public function scopeSearch($query, $pesquisa){
return $query->where('nome', 'like','%' .$pesquisa. '%' );
}
public function roles()
{
return $this->belongsToMany(\App\Models\Acesso\Role::class);
}
}
Can you help me?
o . env ta configured correctly? if yes tries to run this command php Artisan migrate:refresh
– Lodi
edited to ask to leave better explained. As for the refresh command did not work. It says that the database does not exist.
– Lucas Augusto Coelho Lopes
vc created the sgpmehos_bd database in mysql?
– Lodi
Yes, I created the database with that name.
– Lucas Augusto Coelho Lopes
created another mysql user? if it is an updated mysql certainly the root user can not access the database at least I had this problem here
– Bulfaitelo
Do the following then, go to the mysql database to check if there is any table in the sgpmehos_db database and delete all, then try again!
– Lodi
@Bulfaitelo created and still continues with the same error.
– Lucas Augusto Coelho Lopes
@Lodi no table in the bank. :(
– Lucas Augusto Coelho Lopes
The error is that there is no db.Permissions table
– user136447
Jeez, let’s analyze you have a Migration with that name correct?
– Lodi
Rotate this command here
php artisan migrate:refresh --seed
and tell me the result of it.– Bulfaitelo
Hi @Lodi, yes I have.
– Lucas Augusto Coelho Lopes
@Bulfaitelo circled the remote and made the same mistake, my friend.
– Lucas Augusto Coelho Lopes
@Lodi will post the structure of this Migration in the question.
– Lucas Augusto Coelho Lopes
puts the model too, there must be a model, Permissions, looks for protected $table = "Permissions"; if you haven’t added that line and tests again.
– Lodi
I put the model Permission code.
– Lucas Augusto Coelho Lopes
@Lucasaugustocoelholopes is the following in Migration having the model will not interfere in the process as I understood, your problem is when running php Artisan migrate, as very well mentioned here, check carefully the following items: 1. Database sgpmehos_bd created? 2. Is your . env configured correctly? 3. Try running php Artisan migrate:Fresh command, do this only if it is in homologation, do not execute this command in production.
– Raphael Godoi