Category : migration

I’m trying to run migrations from code like this: Artisan::call(‘migrate’); All migrations in the database/migrations folder run perfectly fine but for some reason migrations from vendor files like Sanctum and Telescope are not run at all. (2019_12_14_000001_create_personal_access_tokens_table and 2018_08_08_100000_create_telescope_entries_table) I don’t get any error or anything, they are just not executed. When I run php ..

Read more

I just want to PHP Artisan Migrate, I’m just completed my table on migration but have error Migrating: 2021_09_15_021011_create_dso IlluminateDatabaseQueryException SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘created_date) null, `updated_at` ..

Read more

I am using Laravel 8. I am trying to create a new table and this table does not exist in database and there are not any other table that has the same name. I did the migration and this is the migration code: <?php use IlluminateDatabaseMigrationsMigration; use IlluminateDatabaseSchemaBlueprint; use IlluminateSupportFacadesSchema; class CreateCertificateTable extends Migration { ..

Read more

So I was learning Laravel 8, and came across this problem. At that time I made 4 migrations and their models. When I run the command "php artisan migrate". Then a problem arose in the last migration. This is the 1st migration (2021_08_18_092502_create_masyarakats_table.php) <?php use IlluminateDatabaseMigrationsMigration; use IlluminateDatabaseSchemaBlueprint; use IlluminateSupportFacadesSchema; class CreateMasyarakatsTable extends Migration { ..

Read more

I’m trying to run migrations and three of those have foreign keys. This is one of them: public function up() { Schema::create(‘roomclasses’, function (Blueprint $table) { $table->engine = ‘InnoDB’; $table->id(); $table->timestamps(); $table->string(‘code’, 3); $table->text(‘description’); $table->time(‘time’); $table->float(‘price’); }); Schema::table(‘roomclasses’, function (Blueprint $table) { $table->foreignId(‘days_combination_id’)->constrained(‘days_combinations’); $table->foreignId(‘room_id’)->constrained(‘rooms’); }); } SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint ..

Read more

I created Three migration tables user_container table is for storing user details, admin_table is for storing admin details, blog_table is for storing blogs .admin can create blogs so that’s why i make a foriegn key relationship for admin to blogs table .when i try to migrate the tables i am getting the following error IlluminateDatabaseQueryException ..

Read more

There’s a table in my SQL DB called "projects" and it has a column in it "categories" which is a varchar(255) representation of a php array "[‘category_1’, ‘category_2’, ‘category_3′]" and what i’d like to do is put these categories into a separate table which would be made of a unique integer id in addition to ..

Read more

Schema::create(‘course’, function (Blueprint $table) { $table->integer(‘courseId’)->autoIncrement(); $table->string(‘courseDisplayName’); $table->string(‘courseUniqueName’)->unique(); $table->string(‘courseAddedBy’); $table->dateTime(‘createdOn’); $table->dateTime(‘lastUpdated’); $table->softDeletes(); }); Above given is my course table. To rename the courseId column in it to id, i used the below code. Schema::table(‘course’, function (Blueprint $table) { $table->renameColumn(‘courseId’, ‘id’); }); it shows the migration error – IlluminateDatabaseQueryException SQLSTATE[42703]: Undefined column: 7 ERROR: column "courseid" ..

Read more

I want to display created_at as a timestamp like this : created_at : 1625501162 so this is my created_at column in migration: $table->string(‘created_at’)->Carbon::now()->timestamp; Now I want this field to be created automatically when a new record is created and record the current time. so when i change the line to this : $table->string(‘created_at’)->useCurrent(Carbon::now()->timestamp); gives me ..

Read more

I’m trying to add a couple of foreign keys to a pivot table, like thus:- public function up() { Schema::create(‘posts’, function (Blueprint $table) { $table->bigIncrements(‘id’); $table->unsignedInteger(‘user_id’); $table->string(‘author’); $table->string(‘title’); $table->longText(‘content’); $table->timestamps(); $table->engine = ‘InnoDB’; }); } public function up() { Schema::create(‘tags’, function (Blueprint $table) { $table->bigIncrements(‘id’); $table->string(‘name’); $table->timestamps(); $table->engine = ‘InnoDB’; }); } public function up() ..

Read more

I’m using Laravel migration to add new column location in the table books <?php class AddNewColumn extends Migration { public function up() { Schema::table(‘books’, function (Blueprint $table) { $table->text(‘location’)->nullable()->after(‘description’); }); } } I want to add some predefined location value for each record of "book". I get it from another table called "locations". So for ..

Read more