💡 Add the column nullable and write in with the code
💡 Make the property and the getter nullable
// Model
class User
{
+ /**
+ * @ORM\Column(type="int", nullable=true)
+ */
+ private ?string $age = null;
+ public setAge(int $age){};
+ public getName(): ?int {};
+ }
// SQL Migration
+ ALTER TABLE user ADD age int DEFAULT NULL
💡 Update all nullable rows, make the column not NULL
💡 Make the property and the getter not null
// Model
class User
{
/**
- * @ORM\Column(type="int", nullable=true)
+ * @ORM\Column(type="int", nullable=false)
+ */
- private ?string $age = null;
+ private string $age;
public setAge(int $age){};
- public getAge(): ?int {};
+ public getAge(): int {};
}
// SQL Migration
+ UPDATE user set age = 18 WHERE age IS NULL; // populate empty rows with your strategy
+ ALTER TABLE user ALTER age SET NOT NULL
You mean
getAge()
instead ofgetName()
right?