Float function creates an column where the datatype is double

So I'm creating a table in in my database for charts that I want to display. When I run this migration (see code below) and look in the database (see picture) it says in the datatype column that it's an double. I know how to fix the problem but it's in: "/vendor/laravel/framework/src/Illuminate/Database/Schema" So my question is if everyone has the same problem. My code in the migration:
public function up(): void
{
Schema::create('TestName', function (Blueprint $table) {
$table->id();
$table->dateTime('Datum' );
$table->float('WP_V_L1_N') -> nullable();
$table->float('WP_V_L2_N') -> nullable();
$table->float('WP_V_L3_N') -> nullable();
$table->float('WP_V_L1_L2') -> nullable();
$table->float('WP_V_L1_L3') -> nullable();
$table->float('WP_V_L2_L3') -> nullable();
$table->float('WP_A_L1') -> nullable();
$table->float('WP_A_L2') -> nullable();
$table->float('WP_A_L3') -> nullable();
$table->float('WP_kW_L1') -> nullable();
$table->float('WP_kW_L2') -> nullable();
$table->float('WP_kW_L3') -> nullable();
$table->float('WP_kW_Tot') -> nullable();
$table->float('WP_WH_Tot') -> nullable();
$table->float('WP_kWH_Tot') -> nullable();
$table->float('WP_VarH_Tot') -> nullable();
$table->float('WP_Hz') -> nullable();
});
}
public function up(): void
{
Schema::create('TestName', function (Blueprint $table) {
$table->id();
$table->dateTime('Datum' );
$table->float('WP_V_L1_N') -> nullable();
$table->float('WP_V_L2_N') -> nullable();
$table->float('WP_V_L3_N') -> nullable();
$table->float('WP_V_L1_L2') -> nullable();
$table->float('WP_V_L1_L3') -> nullable();
$table->float('WP_V_L2_L3') -> nullable();
$table->float('WP_A_L1') -> nullable();
$table->float('WP_A_L2') -> nullable();
$table->float('WP_A_L3') -> nullable();
$table->float('WP_kW_L1') -> nullable();
$table->float('WP_kW_L2') -> nullable();
$table->float('WP_kW_L3') -> nullable();
$table->float('WP_kW_Tot') -> nullable();
$table->float('WP_WH_Tot') -> nullable();
$table->float('WP_kWH_Tot') -> nullable();
$table->float('WP_VarH_Tot') -> nullable();
$table->float('WP_Hz') -> nullable();
});
}
Code in blueprint that needs to be changed: (in my case)
/**
* Create a new float column on the table.
*
* @param string $column
* @param int $precision
* @return \Illuminate\Database\Schema\ColumnDefinition
*/
public function float($column, $precision = 53)
{
return $this->addColumn('float', $column, compact('precision'));
}
/**
* Create a new float column on the table.
*
* @param string $column
* @param int $precision
* @return \Illuminate\Database\Schema\ColumnDefinition
*/
public function float($column, $precision = 53)
{
return $this->addColumn('float', $column, compact('precision'));
}
To this:
/**
* Create a new float column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
*/
public function float($column)
{
return $this->addColumn('float', $column);
}
/**
* Create a new float column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
*/
public function float($column)
{
return $this->addColumn('float', $column);
}
No description
2 Replies
Lara Zeus
Lara Zeus5d ago
They both represent floating point numbers. A FLOAT is for single-precision, while a DOUBLE is for double-precision numbers. if you want to change the precision, pass it as a second param
$table->float('WP_A_L1',precision: 7)->nullable();
$table->float('WP_A_L1',precision: 7)->nullable();
note that this is laravel related, for more https://laravel.com/docs/master/migrations#column-method-float
Rejev
RejevOP4d ago
Good to know, thanks

Did you find this page helpful?