Welcome Guest, Not a member yet? Register   Sign In
id convention rule
#1

Hello to everyone
Can I change the column name 'id' for the primary key of a table to a name of my own favor?
thanks
Panagiotis
Reply
#2

(This post was last modified: 08-11-2022, 07:51 AM by captain-sensible.)

yes you can call it ID ; stick to something that makes sense , that you stick to - can't remember rules on underscore in name, but its the characteristics you pick that are important , i have mine to autoincrement and take this into account when i create a new entry



`ID` INTEGER PRIMARY KEY AUTOINCREMENT,


but , if there is data and you rename it, then you will have to adjust code elsewhere. For instance this is the start of a product model

Code:
class ProductModel extends Model

{

protected $table      = 'products';
protected $primaryKey = 'Id';  //i could have called this 'fred' but ID , iD or id is good
protected $allowedFields = ['image','imageTitle','slug','category','info','price'];
protected $limit;
protected $offset;
protected $Id;
protected $imageTitle;
protected $slug;
protected $category;
protected $info;
CMS CI4     I use Arch Linux by the way 

Reply
#3

By rules every table should have an id column and be indexed, just makes life easier.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB