19

I have two fields i need to increment the character limit on. I're read through the documentation and to my surprise i found no option for it. Is it possible to do? If not, how should i go about solving this?

I could drop the column and re-create it with the correct properties, but i don't want to loose any data in the database.

qwerty
  • 5,166
  • 17
  • 56
  • 77

4 Answers4

26

For Laravel 4

DB::update('ALTER TABLE `my_table` MODIFY `my_column` VARCHAR(<new length>)');
ademers
  • 967
  • 3
  • 15
  • 24
24

Use Raw Queries:

/**
 * Make changes to the database.
 *
 * @return void
 */
public function up()
{
  DB::query('ALTER TABLE mytable MODIFY mycolumn VARCHAR(new-length)');
}

/**
 * Revert the changes to the database.
 *
 * @return void
 */
public function down()
{
  DB::query('ALTER TABL mytable MODIFY mycolumn VARCHAR(old-length)');
}

Replace mytable, mycolumn, new-length and old-length.

For Laravel 5+ replace DB::query with DB::statement.

NARKOZ
  • 27,203
  • 7
  • 68
  • 90
17

For Laravel 5:

Schema::table('users', function($table)
{
    $table->string('name', 50)->change();
});

Check docs for further info.

Yauheni Prakopchyk
  • 10,202
  • 4
  • 33
  • 37
1

Use `` for the column name if the name is a keyword for the system. Otherwise you will get an "Syntax error or access violation."

DB::query("alter table MYTABLE modify `MYCOLUMN` varchar(new-length)");
Nate Hat
  • 408
  • 4
  • 11