php - Laravel Migration - Adding Check Constraints In Table -


i want create table in laravel migration this-

create table payroll (  id int primary key,   positionid int,  salary decimal(9,2)   check (salary < 150000.00) ); 

what have done is-

schema::create('payroll', function (blueprint $table) {     $table->increments('id');     $table->integer('positionid ');     $table->decimal('salary',9,2);     //$table->timestamps(); }); 

but can't create this-

 check (salary < 150000.00) 

can please tell, how implement check constraints in laravel migration ?

adding constraints not supported blueprint class (at least of laravel 5.3), is possible add constraints tables directly migrations, using database statements.

in migration file,

public function () {     schema::create('payroll', function (blueprint $table) {         $table->increments('id');         $table->integer('position_id');         $table->decimal('salary',9,2);     });      // add constraint     db::statement('alter table payroll add constraint chk_salary_amount check (salary < 150000.00);'); } 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -