In my laravel 5.7 app I use migration file, hwich I use about 5 monthes with creation of 4 tables(3 of last I used from one plugin ) in 1 file, but suddenly I got error running it :
Migrating: 2018_07_13_150151_create_votes_table
Illuminate\Database\QueryException : SQLSTATE[42S02]: Base table or view not found: 1146 Table 'Vt.taggables' doesn't exist (SQL: select `tag_id` from `taggables` where `taggable_id` = 1 and `taggable_type` = App\Vote)
at /mnt/_work_sdb8/wwwroot/lar/votes/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Exception trace:
1 Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42S02]: Base table or view not found: 1146 Table 'Vt.taggables' doesn't exist")
/mnt/_work_sdb8/wwwroot/lar/votes/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:63
2 PDOException::("SQLSTATE[42S02]: Base table or view not found: 1146 Table 'Vt.taggables' doesn't exist")
/mnt/_work_sdb8/wwwroot/lar/votes/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:61
Please use the argument -v to see more details.
database/migrations/2018_07_13_150151_create_votes_table.php:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use App\User;
use App\Vote;
use App\Taggable as MyTaggable;
use App\Tag;
use App\TagDetail;
use App\VoteCategory;
class CreateVotesTable extends Migration
{
private $users_tb;
private $votes_tb;
private $tags_tb;
private $taggables_tb;
private $tag_details_tb;
private $vote_categories_tb;
public function __construct()
{
$this->users_tb= with(new User)->getTable();
$this->votes_tb= with(new Vote)->getTable();
$this->tags_tb= with(new Tag)->getTable();
$this->taggables_tb= with(new MyTaggable)->getTable();
$this->tag_details_tb= with(new TagDetail)->getTable();
$this->vote_categories_tb= with(new VoteCategory)->getTable();
}
public function up()
{
Schema::create($this->votes_tb, function (Blueprint $table) {
$table->increments('id');
$table->string('name', 255)->unique();
$table->string('slug', 260)->unique();
$table->mediumText('description');
$table->integer('creator_id')->unsigned();
$table->foreign('creator_id')->references('id')->on($this->users_tb);//->onDelete('RESTRICT');
$table->integer('vote_category_id')->unsigned();
$table->foreign('vote_category_id')->references('id')->on($this->vote_categories_tb);//->onDelete('RESTRICT');
$table->boolean('is_quiz')->default(false);
$table->boolean('is_homepage')->default(false);
$table->enum('status', ['N', 'A', 'I'])->comment(' N=>New, A=>Active, I=>Inactive');
$table->integer('ordering')->unsigned();
$table->string('image', 100)->nullable();
$table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->nullable();
$table->index(['created_at'], 'votes_created_at_index');
$table->index(['is_quiz', 'status'], 'votes_is_quiz_status_index');
$table->index(['ordering', 'status'], 'votes_ordering_status_index');
$table->index(['is_homepage', 'status'], 'votes_is_homepage_status_index');
$table->index(['creator_id', 'status', 'name'], 'votes_creator_id_status_name_index');
$table->index(['vote_category_id', 'status', 'name'], 'votes_vote_category_id_status_name_index');
});
Schema::create($this->tags_tb, function (Blueprint $table) {
$table->increments('id');
$table->json('name');
$table->json('slug');
$table->string('type')->nullable();
$table->integer('order_column')->nullable();
$table->timestamps();
});
Schema::create($this->taggables_tb, function (Blueprint $table) {
$table->increments('id');
$table->integer('tag_id')->unsigned();
$table->integer('taggable_id')->unsigned();
$table->string('taggable_type');
$table->foreign('tag_id')->references('id')->on($this->tags_tb)->onDelete('cascade');
});
Schema::create($this->tag_details_tb, function (Blueprint $table) {
$table->increments('id');
$table->integer('tag_id')->unsigned()->unique();
$table->foreign('tag_id')->references('id')->on($this->tags_tb)->onDelete('cascade');
$table->string('image', 100)->nullable();
$table->text('description');
});
Artisan::call('db:seed', array('--class' => 'votesInitData'));
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists($this->taggables_tb);
Schema::dropIfExists($this->tag_details_tb);
Schema::dropIfExists($this->tags_tb);
Schema::dropIfExists($this->votes_tb);
}
}
If seems to me that the onmmly thing I modified that using of prefix for tables name, which I set in constructor of any model app/Tag.php:
<?php
namespace App;
use Spatie\EloquentSortable\Sortable;
use Illuminate\Database\Eloquent\Model;
use App\Http\Traits\HasSlug;
use App\Http\Traits\funcsTrait;
class Tag extends Model implements Sortable
{
use funcsTrait;
public function __construct()
{
parent::__construct();
$this->table = config('app.db_prefix').'tags';
}
Any idea why this error and how to fi it ?
Thanks!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire