Add unique key to existing column with Forge |
08-17-2022, 01:32 PM
(This post was last modified: 08-17-2022, 01:35 PM by captain-sensible. Edit Reason: wasn't paying attention he said via Forge so added last sentence )
lets look at an example of table creation :
Code: CREATE TABLE "admin" ( In the above the id field is set to be an integer , its a primary key and unique. So entries might be 1,2,3 etc the entries are integers and also unique, there can only be one 3, one 2 . Also the creation is set to autoincrement . This takes the headache to a degree of only having one instance, because if the last entry was 2, then the next one will be done to 3 ,without thinking. Now the other thing is i can not have another field called id, i could have a field called ID, and have characteristic of unique also with integers . So i could have also 1.2 ,3 but to my understanding, there can only be one primary key. So suppose you created a table but forgot to add a field called 'id' if it were a sqlite3 table my approach would be to use sqlitebrowser ( https://sqlitebrowser.org/) ; its an easy GUI and you would simply if on Linux get ot from your repo. eg : Code: [andrew@darkstar:~][1]$ sudo pacman -Qi sqlitebrowser (08-17 21:28) Now i just typed all that , then looked at the title WITH Forge - so i guess its not going to be much help. But you know what i will leave it for those new to databases
Code: $this->forge->addField([ Now in this instance primary key is added. need to update this table to add unique key here is scenario 'code' field need to be unique based on 'account_id'. A unique key 'account_id_code' is required here.
Best Regards,
ST |
Welcome Guest, Not a member yet? Register Sign In |