Questions tagged [laravel-migrations]

Database Migrations in Laravel are the way to create and alter database schema.

Introduction

Migrations are a type of version control for your database. They allow a team to modify the database schema and stay up to date on the current schema state. Migrations are typically paired with the Schema Builder to easily manage your application's schema.

Creating Migrations

To create a migration, you may use the make:migration command on the Artisan CLI:

php artisan make:migration create_users_table

The migration will be placed in your database/migrations folder, and will contain a timestamp which allows the framework to determine the order of the migrations.

The --table and --create options may also be used to indicate the name of the table, and whether the migration will be creating a new table:

php artisan make:migration add_votes_to_users_table --table=users

php artisan make:migration create_users_table --create=users

Running Migrations

Running All Outstanding Migrations

php artisan migrate

Note: If you receive a "class not found" error when running migrations, try running the composer dump-autoload command.

Forcing Migrations In Production

Some migration operations are destructive, meaning they may cause you to lose data. In order to protect you from running these commands against your production database, you will be prompted for confirmation before these commands are executed. To force the commands to run without a prompt, use the --force flag:

php artisan migrate --force

Rolling Back Migrations

Rollback The Last Migration Operation:

php artisan migrate:rollback

Rollback all migrations:

php artisan migrate:reset

Rollback all migrations and run them all again:

php artisan migrate:refresh

php artisan migrate:refresh --seed

For more information visit Laravel migrations reference.

489 questions
-1
votes
1 answer

Laravel: last migration

i'm using laravel and working on migrations. I am looking for records of the implementation of migrations. How does Laravel find out how far the migrations have run? Because I have checked that each migraine only runs once and will not run in…
-1
votes
1 answer

ErrorException : Array to string conversion during php artisan migrate:fresh

Trying to set a column as a dateTime type, and to default as the current time and date. However, I keep getting the Error mentioned in the title... This issue in question is related to the 'dateAccepted' field, the 'dateSubmitted' will probably also…
-1
votes
2 answers

How to make a foreign key not using primary key

I have a migration on Laravel for table pasien like this : public function up() { Schema::create('pasien', function (Blueprint $table) { $table->string('No_RM'); $table->timestamps(); $table->primary('No_RM'); …
Adhik Mulat
  • 538
  • 2
  • 10
  • 39
-1
votes
1 answer

How to create a master migration class that would call all your migration classes?

In Laravel the order in which you create your migration and seeders are essential. When these are run in artisan, if there are any foreign keys in a class(table), and one is executed before the one that is being referenced, the execution will stop,…
Marc DG
  • 51
  • 10
-1
votes
1 answer

Laravel Divide DB column on two

Usernames are stored in a DB in one column, how I can divide this column on first name and last names columns. I am thinking about create a loop and run through fullname column split first name and second name by space and store them in…
qr11
  • 443
  • 2
  • 5
  • 25
-1
votes
2 answers

Column not found: 1054 Unknown issue in laravel 4

I face this issue when display one-to-many relationship in laravel 4 SQLSTATE[42S22]: Column not found: 1054 Unknown column 'subject_start.teacher_subject_id' in 'where clause' (SQL: select * from `subject_start` where…
Muhammad Atallah
  • 976
  • 2
  • 12
  • 34
-2
votes
1 answer

How to write a where condition in laravel query?

I write one query which will return true or false by using exists() function in laravel like this $a=$item->conditions()->exists(); The above query works fine ,now i want to extend the query with where condition that will check weather the status…
Code cracker
  • 316
  • 1
  • 5
  • 20
-2
votes
1 answer

Error Preserved While Login in laravel

I've created migration with new column isBan for users but when I want to get not banned users, I have this error when login in my page: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'isBan' in 'where clause' (SQL: select * from users…
-3
votes
1 answer

How i create i deep relation in laravel?

I want to make a relation between teacher, class, and student. A teacher has only one class and each class have many students. My question is that which relation I use Laravel to create this relation?
1 2 3
32
33