Changing column type after baking

I’ve generated a controller, table, and entity using bake against a table, and done some modifications to the entity to allow me to manually insert the entity ID. I originally created the id as an integer, but the system that generates the ids for me is producing numbers that require me to use a bigint, rather than an int.

That’s easy enough to do in the DB, but somewhere Cake is still trying to insert the largest possible integer (2147483647) rather than the larger integer the system is handing me. Is it possible to remap the Table to understand that id is now a bigint, rather than an int, without having to rebake the objects?


You have to rebuild the orm cache. I think that should do it

That is interesting! But it didn’t work. Here’s an example of what I’m talking about.

The DB

CREATE TABLE public.schedules
  id bigint NOT NULL,
  job_id integer,
  user_id integer,
  start_date timestamp without time zone,
  end_date timestamp without time zone,
  CONSTRAINT pk_schedules_id PRIMARY KEY (id),

The insert request data

"id":"1475881942413",  -- This is a bigint
"start_date":"2017-02-22 08:10",
"end_date":"2017-02-22 12:35"

What ends up in the DB

east=# select * from schedules;
     id     | job_id | user_id |     start_date      |      end_date
 2147483647 |     17 |      24 | 2017-02-22 08:10:00 | 2017-02-22 12:35:00
(1 row)

You can see that id is simply the maximum scale for Postgres’ integer data type (4 bytes) when it was declared as bigint (8 bytes.)

Any clues?

So after a bit of digging, I think this is actually a limitation on PHP’s integer size on windows platforms. I just created a simple test controller from scratch against a simple table with a bigint defined id column, and it demonstrates the exact same behavior. The debugger SQL log shows the insertion as

INSERT INTO tests (id, description) 
    2147483647, 'This better be a big damn int.'

While the request data clearly shows

id: 1475881942413
description: This better be a big damn int.

The PHP docs tell me

The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that’s 32 bits signed). 64-bit platforms usually have a maximum value of about 9E18, except on Windows prior to PHP 7, where it was always 32 bit

Since I’m developing on a windows platform, PHP ints are always going to be 32 bits, which sucks.

How hard is it to upgrade to PHP 7 underneath Cake?

AFAIK CakePHP 3.0.7 can run on PHP7
So an updated CakePHP installation should works without problems

Unfortunately, that’s not really an option for me. I ended up changing the data type to varchar so it treats the ID like a string. Now I’m in typecasting hell. :slight_smile:

Why not?
Any updated 3.x run in PHP7 (not only 3.0.x)

Because a platform upgrade on production systems is a whole lot of testing that I don’t have time for right now.