This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hi Guys,
in fields.yaml i didn't define ID field because it's not in table! but when I click on create I received error which id
column added automatically to it!
why it's occure and what I should to do at this situation!
From the Laravel docs...
This...
Note: Eloquent will also assume that each table has a primary key column named
id
. You may define aprimaryKey
property to override this convention. Likewise, you may define aconnection
property to override the name of the database connection that should be used when utilizing the model.
and this...
Note: Typically, your Eloquent models will have auto-incrementing keys. However, if you wish to specify your own keys, set the
incrementing
property on your model tofalse
.
So try adding these to your model
class Whatever extends Model
{
protected $primaryKey = false;
protected $incrementing = false;
}
Last updated
Thanks Scott, For all of your help.
if we want to define multiple primary keys, is following code true?
public $table = 'table_name';
protected $primaryKey = ['first_key','second_key'];
protected $incrementing = false;
Your model's don't dictate your database structure, you should use migration files for this. Also checkout the Laravel documentation for more information.
Schema::create('table_name', function($table)
{
$table->engine = 'InnoDB';
$table->integer('first_key');
$table->integer('second_key');
$table->primary(['first_key', 'second_key']);
});
Last updated
Dear Scott, I defined migration just doesn't add to my previous reply. my question is after we defined primary keys in our migration file. doesn't need to add primary keys to model? or it should be defined in model file,too?
1-5 of 5