Skip to content

Commit 09a64a1

Browse files
[10.x] Support native column modifying (#8456)
* Update migrations.md * Update migrations.md * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 7c0e1b4 commit 09a64a1

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

migrations.md

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ The `default` modifier accepts a value or an `Illuminate\Database\Query\Expressi
998998
};
999999

10001000
> **Warning**
1001-
> Support for default expressions depends on your database driver, database version, and the field type. Please refer to your database's documentation. In addition, it is not possible to combine raw `default` expressions (using `DB::raw`) with column changes via the `change` method.
1001+
> Support for default expressions depends on your database driver, database version, and the field type. Please refer to your database's documentation.
10021002
10031003
<a name="column-order"></a>
10041004
#### Column Order
@@ -1014,10 +1014,22 @@ When using the MySQL database, the `after` method may be used to add columns aft
10141014
<a name="modifying-columns"></a>
10151015
### Modifying Columns
10161016

1017-
<a name="prerequisites"></a>
1018-
#### Prerequisites
1017+
The `change` method allows you to modify the type and attributes of existing columns. For example, you may wish to increase the size of a `string` column. To see the `change` method in action, let's increase the size of the `name` column from 25 to 50. To accomplish this, we simply define the new state of the column and then call the `change` method:
1018+
1019+
Schema::table('users', function (Blueprint $table) {
1020+
$table->string('name', 50)->change();
1021+
});
1022+
1023+
When modifying a column, you must explicitly include all of the modifiers you want to keep on the column definition - any missing attribute will be dropped. For example, to retain the `unsigned`, `default`, and `comment` attributes, you must call each modifier explicitly when changing the column:
10191024

1020-
Before modifying a column, you must install the `doctrine/dbal` package using the Composer package manager. The Doctrine DBAL library is used to determine the current state of the column and to create the SQL queries needed to make the requested changes to your column:
1025+
Schema::table('users', function (Blueprint $table) {
1026+
$table->integer('votes')->unsigned()->default(1)->comment('my comment')->change();
1027+
});
1028+
1029+
<a name="modifying-columns-on-sqlite"></a>
1030+
#### Modifying Columns On SQLite
1031+
1032+
If your application is utilizing an SQLite database, you must install the `doctrine/dbal` package using the Composer package manager before modifying a column. The Doctrine DBAL library is used to determine the current state of the column and to create the SQL queries needed to make the requested changes to your column:
10211033

10221034
composer require doctrine/dbal
10231035

@@ -1034,25 +1046,7 @@ use Illuminate\Database\DBAL\TimestampType;
10341046
```
10351047

10361048
> **Warning**
1037-
> If your application is using Microsoft SQL Server, please ensure that you install `doctrine/dbal:^3.0`.
1038-
1039-
<a name="updating-column-attributes"></a>
1040-
#### Updating Column Attributes
1041-
1042-
The `change` method allows you to modify the type and attributes of existing columns. For example, you may wish to increase the size of a `string` column. To see the `change` method in action, let's increase the size of the `name` column from 25 to 50. To accomplish this, we simply define the new state of the column and then call the `change` method:
1043-
1044-
Schema::table('users', function (Blueprint $table) {
1045-
$table->string('name', 50)->change();
1046-
});
1047-
1048-
We could also modify a column to be nullable:
1049-
1050-
Schema::table('users', function (Blueprint $table) {
1051-
$table->string('name', 50)->nullable()->change();
1052-
});
1053-
1054-
> **Warning**
1055-
> The following column types can be modified: `bigInteger`, `binary`, `boolean`, `char`, `date`, `dateTime`, `dateTimeTz`, `decimal`, `double`, `integer`, `json`, `longText`, `mediumText`, `smallInteger`, `string`, `text`, `time`, `tinyText`, `unsignedBigInteger`, `unsignedInteger`, `unsignedSmallInteger`, and `uuid`. To modify a `timestamp` column type a [Doctrine type must be registered](#prerequisites).
1049+
> When using the `doctrine/dbal` package, the following column types can be modified: `bigInteger`, `binary`, `boolean`, `char`, `date`, `dateTime`, `dateTimeTz`, `decimal`, `double`, `integer`, `json`, `longText`, `mediumText`, `smallInteger`, `string`, `text`, `time`, `tinyText`, `unsignedBigInteger`, `unsignedInteger`, `unsignedSmallInteger`, `ulid`, and `uuid`.
10561050
10571051
<a name="renaming-columns"></a>
10581052
### Renaming Columns
@@ -1091,7 +1085,6 @@ You may drop multiple columns from a table by passing an array of column names t
10911085
$table->dropColumn(['votes', 'avatar', 'location']);
10921086
});
10931087

1094-
10951088
<a name="dropping-columns-on-legacy-databases"></a>
10961089
#### Dropping Columns On Legacy Databases
10971090

0 commit comments

Comments
 (0)