Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set entity field default value using YML

I need get default value in class file

private $example_field = 0;

When I use this

example_field:
    options:
        default: 0

I got default database value, but when I try to persist without setting "su" I got error (column 'su' cannot be null).

Anyway,

example_field:
    default: 0

Does nothing.

like image 279
Shadow Prince Avatar asked Dec 02 '12 12:12

Shadow Prince


People also ask

How do I change the default value in Java?

Remember, to get the default values, you do not need to assign values to the variable. static boolean val1; static double val2; static float val3; static int val4; static long val5; static String val6; Now to display the default values, you need to just print the variables.

What is the default value of a field?

Default field values automatically insert the value of a custom field when a new record is created. You can use a default value on a formula for some types of fields or exact values, such as Checked or Unchecked for checkbox fields. After you have defined default values: The user chooses to create a new record.

What is the use of default value in the properties?

The DefaultValue property specifies text or an expression that's automatically entered in a control or field when a new record is created. For example, if you set the DefaultValue property for a text box control to =Now(), the control displays the current date and time.


2 Answers

this work for me:

fields:
    my_field:
        options:
            default: 5
like image 93
Frederic Avatar answered Sep 21 '22 13:09

Frederic


The correct definition for a 0 default value would be by using quotes:

example_field:
    options:
        default: '0'
like image 29
Steffen Roßkamp Avatar answered Sep 19 '22 13:09

Steffen Roßkamp