Category : database-migration

I’m building a multi language website using Laravel. To do that I used the https://github.com/mcamara/laravel-localization package. Now I want to save the language as a field at users migrations. This is create_users_table.php: <?php use IlluminateDatabaseMigrationsMigration; use IlluminateDatabaseSchemaBlueprint; use IlluminateSupportFacadesSchema; class CreateUsersTable extends Migration { /** * Run the migrations. * * @return void */ public ..

Read more

when running "php artisan migrate:fresh" command it shows SQLSTATE[42000] error Here is the full error message SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘unsigned not null, created_at timestamp null, updated_at ..

Read more

Table QW has customised ID. I was trying to create a new QW with the id of ‘QWSE123’. It returns error as below SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘QWSE123’ for key ‘PRIMARY’ (SQL: insert into qw (id, updated_at, created_at) values (QWSE123, 2021-08-26 13:02:04, 2021-08-26 13:02:04)) migration Schema::create(‘qw’, function (Blueprint $table) { $table->string(‘id’, 26)->primary(); ..

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

I’m trying to run a Laravel migration which is failing at this line $table->dateTime(‘start_date’)->nullable()->default(‘0000-00-00 00:00:00′); And I’m getting the following error: 1067 Invalid default value for ‘start_date’ even after removing NO_ZERO_DATE and NO_ZERO_IN_DATE values from sql_mode. I’m using XAMPP, and I ran the following commands: SET GLOBAL sql_mode=” SET SESSION sql_mode=” SET sql_mode=” I also ..

Read more

DB::statement(" CREATE VIEW course_market_view AS ( SELECT users.id, users.name, course.id, course.courseUniqueName, skills.id, skills.skill, subjects.id, subjects.subject FROM users LEFT JOIN course ON course.userId=users.id LEFT JOIN skills ON skills.userId=users.id LEFT JOIN subjects ON subjects.userId = users.id ) "); I’ve written the above code in the up method of my migration but when running migrate command, it shows ..

Read more

What all extra changes in laravel code must be made when you customize the columns in the existing users table in LARAVEL 8 public function up() { Schema::create(‘users’, function (Blueprint $table) { $table->increments(‘id’); $table->string(‘Username’); $table->string(‘FirstName’)->nullable(); $table->string(‘LastName’)->nullable(); $table->date(‘DOB’)->nullable(); $table->string(’email’)->unique(); $table->string(‘Address’)->nullable(); $table->integer(‘PhoneNumber’)->nullable(); $table->string(‘password’); $table->string(‘UserType’); $table->rememberToken(); $table->timestamps(); }); } Sourc..

Read more

I’ve got these two tables linked with a one to one relation. How should the seeders be if I want unique foreign keys in sponsored apartments table? Model table Apartments: public function sponsoredapartment() { return $this -> hasOne(SponsoredApartment::class); } Model table Sponsored Apartments public function apartment() { return $this -> belongsTo(Apartment::class); } Migrations Apartments Schema::create(‘apartments’, ..

Read more

First migration file: <?php use IlluminateDatabaseMigrationsMigration; use IlluminateDatabaseSchemaBlueprint; use IlluminateSupportFacadesSchema; class CreateUsersTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create(‘users’, function (Blueprint $table) { $table->id(); $table->string(‘name’); $table->string(’email’)->unique(); $table->timestamp(’email_verified_at’)->nullable(); $table->string(‘password’); $table->rememberToken(); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function ..

Read more

Migration file: <?php use IlluminateDatabaseMigrationsMigration; use IlluminateDatabaseSchemaBlueprint; use IlluminateSupportFacadesSchema; class CreatePostsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create(‘posts’, function (Blueprint $table) { $table->bigIncrements("post_id"); $table->bigInteger("author_id"); $table->string("title"); $table->string("short_title"); $table->string("img")->nullable(); $table->text("descr"); $table->timestamps(); $table->foreign("author_id")->references("id")->on("users"); }); } /** * Reverse the migrations. * * @return void */ public function ..

Read more

I’ve been watching a tutorial on Laravel and there is $table->bigIncrements("id") in a migration file, but when I open the same file there is $table->id() function. Questions: Was there any update in which bigIncrements was replaced by id()? I’ve been searching the net for a while but haven’t found anything about it. Do these functions ..

Read more