mysql - Laravel - how to use foreign primary key that's not an integer? -
I have to set a string column as a primary key of a table, then mention as a foreigner That's the key I'm trying from another table. This is possible Documents per: In my case, I do not want to define a This is an old question, but for the sake of purity, I would like to continue that the present version of the eloquent You can actually use non-numerical primary / foreign key in One thing you just have to do is to set up property
Laravel assumes that each table is a numerical primary key (usually named a ???? ida ???? ) And ensures that the value of this column is unique to each new line added in the table. Laravel works really well until each table has a numerical primary key. Therefore, for your average large application, please make sure that you define the primary key using the scale () method.
id column because it will be useless. The string column that I want to define will act as the primary key. If this is possible, can I find a migration piece of an example?
$ incrementing
false to model that non-autoincrementing ID to use on
class employee spread model {public $ incrementing = false. Also, the migration can be:
schema :: build ('employee', function (blue print $ Table) {$ table- & gt; string ('id') - & gt; elementary (); // ...});
Comments
Post a Comment