PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, February 21, 2022

[FIXED] CakePHP 3 - Save function not generating primary key for database

 February 21, 2022     cakephp-3.0, cakephp-3.x     No comments   

Issue

I have an application I'm working on with Cake 3 and I've baked a bunch of things to get the lay of the land as I'm newer to Cake.

When going to the baked add view for one of my models, filling out the form and submitting, the entry is added to the database but the primary key is blank on the entry. I've been doing some research and in the table class for Cake, I know that it's supposed to be created during the save method. However, I haven't overridden save or anything like that, so I'm a little confused as to why it's not generating the ID field for the primary key.

I was hoping someone might be able to point me in the right direction towards some steps that might help me debug this. Thanks!


Solution

From the Cookbook 3.x:

Rather than using an auto-increment key as the primary key, you may also use char(36). CakePHP will then use a unique 36 character UUID (Text::uuid) whenever you save a new record using the Table::save() method.

Try converting you id field in your MySQL table from

VARCHAR(36)

to

CHAR(36)


Answered By - Inigo Flores
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing