Category : laravel-migrations

So I have this migration public function up() { Schema::table(‘xxx’, function (Blueprint $table) { $table->foreign(‘aaa’,’bbb’) // handle identifier name too long ->references(‘id’)->on(‘aaa_table’)->onDelete(‘cascade’)->onUpdate(‘cascade’); }); } I want create the down() function / reverse the migration for remove this foreign key. What I have tried here: public function down() { Schema::table(‘xxx’, function (Blueprint $table) { // implement ..

Read more

I have 2 migrations, the first one has the following name 2019_11_06_171637_create_settings_table.php and structure: class CreateSettingsTable extends Migration { public function up() { Schema::create(‘settings’, function (Blueprint $table) { //code }); } //function down } the second one has the following name 2020_07_08_246856_create_settings_table.php and structure: class CreateAnotherSettingsTable extends Migration { public function up() { Schema::create(‘another_settings’, function ..

Read more

I want to set the played column as primary key while keeping its type as timestamp. public function up() { Schema::create(‘tb_played’, function (Blueprint $table) { $table->unsignedInteger(‘artist_id’); $table->foreign(‘artist_id’)->references(‘artist_id’)->on(‘tb_artist’); $table->unsignedInteger(‘album_id’); $table->foreign(‘album_id’)->references(‘album_id’)->on(‘tb_album’); $table->unsignedInteger(‘track_id’); $table->foreign(‘track_id’)->references(‘track_id’)->on(‘tb_track’); $table->timestamp(‘played’); $table->timestamps(); }); } Source: Laravel Sta..

Read more

I have this Laravel migration structure: class CreateWarehouseProductTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create(‘warehouse_products’, function (Blueprint $table) { $table->bigIncrements(‘id’); $table->integer(‘product_id’)->default(0); $table->integer(‘warehouse_id’); $table->integer(‘free_amount’)->default(0); $table->integer(‘booked_amount’)->default(0); // … $table->timestamps(); }); } // … } I need to create a daily backup from warehouse products and for ..

Read more

I tried to do the migration and I ran into this error: Syntax error or access violation 1064. I looked at other similar problems but I couldn’t find the solution to this problem. Please help, and thanks in advance. Schema::create(‘posts’, function (Blueprint $table) { $table->bigIncrements(‘id’); $table->unsignedBigInteger(‘author_id’); $table->foreign(‘author_id’)->references(‘id’)->on(‘authors’)->onDelete(‘cascade’); $table->string(‘title’); $table->text(‘excerpt’); $table->longText(‘body’); $table->binary(‘post_image’); $table->timestamp(‘published_at’)->nullable(); $table->timestamps(); $table->softDeletes(); }); ..

Read more