Symfony2 - fos create super admin custom field required - deployment

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 my#mail.com 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...

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.

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.

Related

Is it possible to manually define a single attribute for a Hanami/ROM entity?

we're building a Hanami app and one of my entities has an attribute of tsvector. I've added this via a migration which ran ok:
Hanami::Model.migration do
change do
alter_table :segments do
add_column :ts_content, :tsvector, generated_always_as: [to_tsvector: [:simple, :content]]
end
end
end
When I start the server, or run a rake task for example, this is what I get:
ROM::Schema::MissingAttributesError: missing attributes in ROM::Relation::Name(segments) schema: :ts_content
I gather that tsvector is not a supported type. So the schema can't be inferred. Discussion in one of the issues related to this suggests I need to define the attribute manually. Where and how do I do this for a single attribute?
If I do it in the entity I suppose I have to do it for all the attributes, right?
Best, Seba

Laravel duplicate DB entry error page

I made a simple form, that saves data in a DB in Laravel 5.x with the the use of Forms package.
One of the "elements" is unique, which I have made a rule that it must be unique. I made that in the migrations folder. When i run the site, the form works as it should. When you do not enter all the fields it refreshesh with all the data still inside. But when i input a duplicate (in the unique required filed) it does not refresh the site, but throws an error:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry

Can't create migration to add new column to table: Invalid column name

I'm trying to add a column to an existing table. It is simply a string column, not involved in any kind of keys and this is the only change I'm trying to make. I am creating the migration with the powershell call
dotnet ef migrations add [migration name] --context [context name]
As I've done many times before. I get an error that says.
An error occurred while calling method 'BuildWebHost' on class 'Program'. Continuing without the application service provider. Error: Invalid column name '[column id]'.
Unable to create an object of type 'DashboardContext'. Add an implementation of 'IDesignTimeDbContextFactory<[context name]>' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.
Apparently this error means that the column doesn't exist, but that's precisely why I'm trying to create the migration - to add it.
EDIT: It turns out that adding the migration includes a call to Startup->Configure which in my case accessed that table. Any info on why that is the case would be appreciated. Meanwhile I got around it by commenting that code out while creating the migration.

web2py Validation

I would like to know validation is a must, on fields which are not present on the form but are available in the table. Does marking them as NULL in the define_table make them validated only when they are present in the form?
The form validators apply only to forms, so will not affect fields that are not present in the form. I'm not sure what you mean by marking a field as NULL, but if you are referring to Field(..., notnull=True), that executes the SQL NOT NULL statement when the database table is first created (assuming DAL migrations are enabled). That option is enforced by the database itself whenever a record is inserted or updated (via a form or any other method). If a notnull field is left empty, it will result in an operational error from the database.

Zend Framework - Registration Form, Elegant way to check for duplicate usernames?

Does Zend Framework provide an elegant way to check if the username already exist in the database?
Or is my only option to code a validator using a combination of php if/else and mysql select statements?
You can add a validator which will check in database if username already exist, if so it will notice the user. I am assuming you are using Zend_Form and Zend_Db_Table with at least one default db table database.
For example:
$element = new Zend_Form_Element_Text('username');
$element->setLabel('User:')
->addValidator(new Zend_Validate_Db_NoRecordExists('user', 'username'))
->setRequired(true);
$this->addElement($element);
You will pass 2 parameters to validator, first is table name and second is the column you want to check.
That's it!