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
0
votes
1 answer

laravel update table with artisan migration

I simply create a migration and run migrate with commands here is the commands I type and the result I get; Serkan:itsp mehmet$ php artisan make:migration alter_table_rates --path="database/migrations/v141/" --table="rates" Created Migration:…
TyForHelpDude
  • 4,828
  • 10
  • 48
  • 96
0
votes
1 answer
0
votes
2 answers

How to use Migration in Laravel?

I'm currently beginner of laravel. I'm studying laravel 5.2 from it's official docs. After studing migration in laravel, I'm very much clear about it's migration concept. But on practicing by scripting code, I come a problem. The problem is that as…
Akshay Vaghasiya
  • 1,597
  • 9
  • 36
  • 60
0
votes
2 answers

incomplete migrations- stuck in generating new migrations

I am having a very bad situation here, working on a Laravel 5 project. previously developed by another developer. That developer at start created couple of tables using migration generators and added some columns using migrations. After that, he…
0
votes
2 answers

Laravel 5.1 migration new table not working

I have got some problem with migration. I create new migrate file php artisan make:migration create_menu_table --create=menu then i edit the new Migration file and when i try migrate it's not working I tried: php artisan migrate php artisan migrate…
Pionas
  • 346
  • 1
  • 4
  • 15
0
votes
1 answer

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db.store' doesn't exist

When I try to save data from laravel form to a database table I am getting the following exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db.store' doesn't exist (SQL: select count(*) as aggregate from store where name =…
0
votes
1 answer

Laravel Migration Failed

I'm having a bit of trouble with Laravel Migrations. I've recently stopped developing on C9 and decided to try out Nitrous.io instead - however I'm unsure whether my error is related to this. I also decided to change from sqlite to mysql. Since I'm…
0
votes
2 answers

Laravel: Something wrong with migration command

I find this one so weird, can you point what am I missing? I run "php artisan migrate" its working well. When I do this line "php artisan migrate:refresh" or "php artisan migrate:reset" Error below: so I checked the file 2014_10_12_0000 ... it was…
Kuya A
  • 351
  • 2
  • 18
0
votes
2 answers

Pivot Table for Matches with host team and guest team in Laravel5

I want to have matches with 2 teams in my App. Currently I implemented this with a simple hasMany/belongsToMany relationship. Tables: teams, matches, match_team (match_id, team_id) Team Model ... public function matches() { return…
0
votes
2 answers

Laravel 4.2 and migrate make not working

I create a project based on the book Getting Started with Laravel 4. So, I create two files in app/models/ - Cat.php and Breed.php with this content: Cat.php
User002
  • 13
  • 4
0
votes
1 answer

laravel 5 migration add some primary keys to my database table. how to prevent form it?

When i create Laravel5 migration as follows it adds "linkdesc" column as a primary key. when i read the documentation of laravel5 migration it does not mentioned that $table->text('description'); this gives a primary key in database. is there any…
kasunb
  • 157
  • 1
  • 9
0
votes
1 answer

What's the best way to drop a Laravel 4.2 table?

I've been creating tables using migrations per the documentation, and now I've rebuilt a section of my website and now I don't need one of my older tables. I could: A) Create a new migration file and tell it to drop the table in the "up" function,…
Citizen
  • 12,430
  • 26
  • 76
  • 117
0
votes
1 answer

defining relationship issue in laravel

How to define relationship between below tables. Class->belongsToMany('Student'); Student->belongsToMany('Class'); Class table and Student table pivoted by class_student table I have Payment table as below $table->increments('id'); …
Ryan Exlay
  • 361
  • 1
  • 3
  • 12
0
votes
1 answer

create first user in Laravel 5

This is my first time using Laravel 5. Never experienced with any of other framework like CakePHP, CodeIgniter, Yii, etc. I just know how to use make api REST with slim framework. I already create a table users as I can't access <>/home. I…
Muhaimin
  • 1,643
  • 2
  • 24
  • 48
-1
votes
1 answer

Laravel - artisan migrate takes long time about 3 sec for each table on Ubuntu 22.04 & 23.04

I have installed the latest version of ubuntu 23.04, and there was a problem with artisan migrate. The problem is the process takes about 3 sec for each table to be created! as stated in the image below. After trying many solutions, I thought that…
MElhalees
  • 75
  • 7