#### Category : database-migration

I manually deleted my all tables now i want ot re-migrate my tables. but it shows this error Base table or view not found: 1146 Table ‘mymedia.categories’ doesn’t exist (SQL: select * from categories where categories.deleted_at is null order by id asc) I tried these functions php artisan migrate php artisan migrate –force php artisan ..

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 ..

enter image description here enter image description here enter image description here HELP ME Sourc..

I want to add a column which is an array or json type by the default it should be an empty if i am not passing any value ,and it should take a value (if i pass any value it should take a value otherwise it should take empty/null value automatically).How to acheive this thing ..

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 ..

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(); ..

I am building a dating app using Laravel and each user in my table will have gender, relationship status, body type, ethnicity, religion, sign etc. After I created a migration for each of these should I also create model as well ? I am planning to have a user_details table in which I store the ..

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 { ..

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 I did some changes in my migrations schemas, So i tried to fresh my migrations but i get an error: I will be thankfull for an answer 🙂 My migration that failed: The migration that im realtion to with PK <-> FK The error message: Sourc.. Read more In laravel’s database.php file you can specify the table in your database to keep track of migrations that have run. What I’m wondering is if it’s possible to specify more than 1 table. For example, I have 2 databases. Let’s say the name of the migrations table in database 1 is "migrations1" and the table .. Read more i want to make one to many relationship between the sections table to classrooms and grades but it the foreign key constraint in incorrectly formed at cmd when running migration note my order in tables 1-sections 2-grades 3-classrooms here is my sections code class CreateSectionsTable extends Migration { /** * Run the migrations. * * .. 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 I’m completely new to the views. I’ve written the below code in the up method of my migration but when running migrate command, it shows – Syntax error: 7 ERROR: syntax error at or near "FROM" LINE 13: FROM "users" u. I wanted to join the 4 tables – users, course, skills & subjects and .. Read more Let’s say I want to do an update to my web application. This update includes both PHP code changes and some Database migrations as well. The new version of the code requires the new version of the Database structure. How do you perform this update such that you don’t have your app in a state .. Read more When I run the following two php artisan commands, the first with no –table flag and the second with a –table flag, I get the same code in the generated migration file. While I know that the –table flag is meant to specify the table name to be modified, I also know that the Laravel .. Read more I want the primary key value of a table to start in this form in Laravel: 0001. Here’s what I did:$table->id()->startingValue(0001); But when a record is created, instead of the "0001" pattern it returns 1. Yes, I know 0001 is the same thing as 1. Any idea how I could make it retain that ..

I have a doubt that – when i already have added Schema::dropIfExists(‘location’); – this line to the down method as in the below code , do i necessarily need to give $table->dropSoftDeletes(); – this line too in order to get the deleted_at also removed while i do the migration rollback. public function up() { Schema::create(‘location’, .. 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..

As our project scaled we decided that every single data should belong to companies that created them. Therefore I’m to add a column "data_owner_company_id" that points to the company that owns given record. Yes it’s possible to generate migration to add this column to each model but that is not really feasible since there is ..

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’, ..

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 ..
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 ..