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: README.md
+7-4
Original file line number
Diff line number
Diff line change
@@ -597,10 +597,13 @@ User:
597
597
598
598
## Handling of `NOT NULL` constraints
599
599
600
-
`NOT NULL` in DB migrations is determined by `nullable` and `required` properties of the OpenAPI schema.
600
+
`NOT NULL` in DB migrations is determined by `nullable` properties of the OpenAPI schema.
601
601
e.g. attribute = 'my_property'.
602
602
603
603
- If you define attribute neither "required" nor via "nullable", then it is by default `NOT NULL` ([as per OpenAPI spec](https://github.com/OAI/OpenAPI-Specification/blob/main/proposals/2019-10-31-Clarify-Nullable.md)):
604
+
- `nullable` and `required` of OpenAPI spec is not related. They have separate purpose.
605
+
- `nullable` will help in creating migrations ([`null()`](https://www.yiiframework.com/doc/api/2.0/yii-db-columnschemabuilder#null()-detail) and [`notNull()`](https://www.yiiframework.com/doc/api/2.0/yii-db-columnschemabuilder#notNull()-detail)) only
606
+
- `required` will help in creating model validation rules only
604
607
605
608
```yaml
606
609
ExampleSchema:
@@ -609,7 +612,7 @@ e.g. attribute = 'my_property'.
609
612
type: string
610
613
```
611
614
612
-
-If you define attribute in "required", then it is `NOT NULL`
615
+
-In below example, if you define attribute in "required", then it is `NOT NULL`, because `nullable` is present and it defaults to `false`
613
616
614
617
```yaml
615
618
ExampleSchema:
@@ -620,7 +623,7 @@ e.g. attribute = 'my_property'.
620
623
type: string
621
624
```
622
625
623
-
- If you define attribute via "nullable", then it overrides "required", e.g. allow `NULL` in this case:
626
+
- If you define attribute via "nullable", e.g. allow `NULL` in this case:
624
627
625
628
```yaml
626
629
ExampleSchema:
@@ -632,7 +635,7 @@ e.g. attribute = 'my_property'.
632
635
nullable: true
633
636
```
634
637
635
-
- If you define attribute via "nullable", then it overrides "required", e.g. `NOT NULL` in this case:
638
+
- If you define attribute via "nullable" e.g. `NOT NULL` in this case:
Copy file name to clipboardExpand all lines: tests/specs/x_db_type/edit_column/maria/app/migrations_maria_db/m200000_000000_create_table_alldbdatatypes.php
Copy file name to clipboardExpand all lines: tests/specs/x_db_type/edit_column/maria/app/migrations_maria_db/m200000_000001_change_table_editcolumns.php
+3-3
Original file line number
Diff line number
Diff line change
@@ -7,16 +7,16 @@ class m200000_000001_change_table_editcolumns extends \yii\db\Migration
Copy file name to clipboardExpand all lines: tests/specs/x_db_type/edit_column/maria/app/migrations_maria_db/m200000_000002_create_table_newcolumns.php
Copy file name to clipboardExpand all lines: tests/specs/x_db_type/edit_column/mysql/app/migrations_mysql_db/m200000_000000_create_table_alldbdatatypes.php
Copy file name to clipboardExpand all lines: tests/specs/x_db_type/edit_column/mysql/app/migrations_mysql_db/m200000_000001_change_table_editcolumns.php
+3-3
Original file line number
Diff line number
Diff line change
@@ -7,16 +7,16 @@ class m200000_000001_change_table_editcolumns extends \yii\db\Migration
0 commit comments