You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: migrations.md
+17-24Lines changed: 17 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -998,7 +998,7 @@ The `default` modifier accepts a value or an `Illuminate\Database\Query\Expressi
998
998
};
999
999
1000
1000
> **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.
1002
1002
1003
1003
<aname="column-order"></a>
1004
1004
#### Column Order
@@ -1014,10 +1014,22 @@ When using the MySQL database, the `after` method may be used to add columns aft
1014
1014
<aname="modifying-columns"></a>
1015
1015
### Modifying Columns
1016
1016
1017
-
<aname="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:
1019
1024
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) {
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:
1021
1033
1022
1034
composer require doctrine/dbal
1023
1035
@@ -1034,25 +1046,7 @@ use Illuminate\Database\DBAL\TimestampType;
1034
1046
```
1035
1047
1036
1048
> **Warning**
1037
-
> If your application is using Microsoft SQL Server, please ensure that you install `doctrine/dbal:^3.0`.
1038
-
1039
-
<aname="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`.
1056
1050
1057
1051
<aname="renaming-columns"></a>
1058
1052
### Renaming Columns
@@ -1091,7 +1085,6 @@ You may drop multiple columns from a table by passing an array of column names t
0 commit comments