I have seen this code in CodeIgniter docs.
<?php
$fields = [
'id' => [
'type' => 'INT',
'constraint' => 5,
'unsigned' => true,
'auto_increment' => true,
],
'title' => [
'type' => 'VARCHAR',
'constraint' => '100',
'unique' => true,
],
'author' => [
'type' => 'VARCHAR',
'constraint' => 100,
'default' => 'King of Town',
],
'description' => [
'type' => 'TEXT',
'null' => true,
],
'status' => [
'type' => 'ENUM',
'constraint' => ['publish', 'pending', 'draft'],
'default' => 'pending',
],
];
The id field will translate to INT(5)
. I think an integer should be large enough for id. What is the point of adding length?
I generally use INT
. I am wondering what is the best practice.