Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 - fos create super admin custom field required

I am deploying a SF2.1 project into production.
I have customized the user model so that certain fields are required.
So when I try to create my super admin

$ php app/console fos:user:create admin [email protected] my_pass --super-admin

I'm getting

[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'my_required_field' cannot be null

What is the clean way to manage that ?
I Imagine not manually inserting the user into the table...

like image 545
Pierre de LESPINAY Avatar asked Jan 14 '23 21:01

Pierre de LESPINAY


2 Answers

You should override FOSUserBundle execute() method in /Command/CreateUserCommand.php and create() method in /Util/UserManipulator.php files. By doing that you should be able to add any additional fields to your User entity from the command line.

like image 70
Juan Sosa Avatar answered Jan 25 '23 16:01

Juan Sosa


You can either override the CLI command in order to provide the required field, or just provide a default value in class constructor in case it is a scalar.

like image 33
moonwave99 Avatar answered Jan 25 '23 15:01

moonwave99