# Bake not generating 100% new model-files?

**URL:** <https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265>\
**Category:** Uncategorized\
**Created:** [June 15, 2019, 9:53am UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265 "2019-06-15T09:53:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![drtrppr](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/drtrppr/32/1763_2.png) [@drtrppr](https://discourse.cakephp.org/u/drtrppr)\
**Post date:** [June 15, 2019, 9:53am UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/1 "2019-06-15T09:53:54Z")

</div>

My favourite cakephp-command is ‘cake bake all --everything -f’. My expectation was that using this command I got rid of all the changes I made to the code and should get a fresh build. But apparently at least some changes stay persistent.

For example, first thing I do after baking is changing display fields from id’s to another field. When rebaking, display-fields don’t change back to id’s. Console tells me models are rewritten (no errors), timestamp on file tells me it’s a new file.

Can’t find any info in the manual about this behaviour, is it a bug or is it a feature 🙂

Sometimes I can’t get the baked application working properly after the ‘bake all --everything’, and I just delete all baked files. So I think I’m missing something?

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [June 28, 2019, 8:09pm UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/2 "2019-06-28T20:09:07Z")

</div>

What fields are you using as display fields? The bake often chooses other fields than the ids for me, like “name” or “description” strings, so maybe it’s just being smart enough to choose the fields that you wanted to use?

---

<div class="post-metadata">

**Author:** ![drtrppr](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/drtrppr/32/1763_2.png) [@drtrppr](https://discourse.cakephp.org/u/drtrppr)\
**Post date:** [July 1, 2019, 10:23am UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/3 "2019-07-01T10:23:11Z")

</div>

That’s interesting, I’ve bake never seen choosing another display field, always the ‘id’ (I’m using CakePHP 3.7). Maybe a convention I’m missing?

To test this behaviour, I use two tables, ‘compositions’ (with fields ‘id’, ‘composition’, ‘description’) and ‘items’ (with fields ‘id’, ‘item’, ‘composition\_id’, ‘description’).

Bake generates innitially a model ‘CompositionsTable’ with DisplayField ‘id’. I repeatedly changed it to ‘composition’, ‘description’ and ‘id’ etc., after every bake the DisplayField kept the value I set it manually to.

The list of ‘items’ keeps showing the at that moment intended value for composition as set in the DisplayField.

---

<div class="post-metadata">

**Author:** ![drtrppr](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/drtrppr/32/1763_2.png) [@drtrppr](https://discourse.cakephp.org/u/drtrppr)\
**Post date:** [May 12, 2020, 10:44am UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/4 "2020-05-12T10:44:17Z")

</div>

Stumbling on the same question again. Now using cakephp 4.0.5.

Baked a working prototype based on a table with a lot of non-descriptive column names (like for example ‘\_00023’). Using phpmyadmin I renamed some of them with a descriptive name (‘weight’).

Baking again (‘cake bake all --everything -f’) doesn’t seem to change for example model ‘mytableTable.php’. The validator still uses the old column-names (’-00023’). I expected bake to create new files with the new column names.

I’v seen no errors. I used all kinds of bake-commands like ‘cake bake model mytable --force’. Bake always asks to overwrite when not using --force, my editor always detects a new version of the file. So bake is writing a new file, but what’s is it really doing, and why is it not doing the things I expect it to do?

---

<div class="post-metadata">

**Author:** ![drtrppr](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/drtrppr/32/1763_2.png) [@drtrppr](https://discourse.cakephp.org/u/drtrppr)\
**Post date:** [May 12, 2020, 10:46am UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/5 "2020-05-12T10:46:19Z")

</div>

Deleting manually the src-directory, after bake the new files still use the old column names ??? There is some cache which is being used?

---

<div class="post-metadata">

**Author:** ![drtrppr](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/drtrppr/32/1763_2.png) [@drtrppr](https://discourse.cakephp.org/u/drtrppr)\
**Post date:** [May 12, 2020, 10:49am UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/6 "2020-05-12T10:49:42Z")

</div>

\tmp\cache\models, there is file which references to my table. Deleting this file, and bake works as expected.

How to configure the cache that when the table changes the file gets updated?

---

<div class="post-metadata">

**Author:** ![drtrppr](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/drtrppr/32/1763_2.png) [@drtrppr](https://discourse.cakephp.org/u/drtrppr)\
**Post date:** [May 12, 2020, 11:10am UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/7 "2020-05-12T11:10:20Z")

</div>

The awnser will be somewhere in [https://book.cakephp.org/4/en/core-libraries/caching.html](https://book.cakephp.org/4/en/core-libraries/caching.html)

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [May 12, 2020, 2:20pm UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/8 "2020-05-12T14:20:22Z")

</div>

For the cache to automatically update whenever the table is changed would require that it check the table structure every time, which entirely defeats the purpose of caching. If you enable debug mode, it clears the cache much more frequently, and of course you can clear it yourself at any time. There’s even a `bake` command to clear it for you.

---

<div class="post-metadata">

**Author:** ![dreamingmind](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dreamingmind/32/1857_2.png) [@dreamingmind](https://discourse.cakephp.org/u/dreamingmind)\
**Post date:** [May 12, 2020, 2:59pm UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/9 "2020-05-12T14:59:52Z")

</div>

`title` and `name` are the default choices. I believe these choices do get baked in too.

 ![Screen Shot 2020-05-12 at 7.56.32 AM](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/b/b2d85a860d0f2c9e6e73f416d7a0262fecbf77fd.png)

In fact, here are the ‘bake’ callers of that method, so yeah, they bake in.

 ![Screen Shot 2020-05-12 at 8.02.09 AM](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/f/f89a80acf1176fd4addacf06399146acbc3810f4.png)

---

<div class="post-metadata">

**Author:** ![drtrppr](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/drtrppr/32/1763_2.png) [@drtrppr](https://discourse.cakephp.org/u/drtrppr)\
**Post date:** [May 12, 2020, 4:47pm UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/10 "2020-05-12T16:47:23Z")

</div>

Will look into bake command to clear the cache, that should avoid the experienced problems.

---

<div class="post-metadata">

**Author:** ![drtrppr](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/drtrppr/32/1763_2.png) [@drtrppr](https://discourse.cakephp.org/u/drtrppr)\
**Post date:** [May 12, 2020, 4:51pm UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/11 "2020-05-12T16:51:25Z")

</div>

Thanks. Did I miss this in the cookbook, or isn’t this feature described? Will read again.

---

<div class="post-metadata">

**Author:** ![dreamingmind](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dreamingmind/32/1857_2.png) [@dreamingmind](https://discourse.cakephp.org/u/dreamingmind)\
**Post date:** [May 12, 2020, 5:05pm UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/12 "2020-05-12T17:05:02Z")

</div>

I read it at some point in the past but couldn’t find it again in 4 docs. Didn’t look too hard though

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [May 12, 2020, 5:12pm UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/13 "2020-05-12T17:12:53Z")

</div>

Sorry, I mis-typed. It’s a [`bin/cake` command](https://book.cakephp.org/4/en/console-commands/schema-cache.html), not a `bake` command.

---

<div class="post-metadata">

**Author:** ![drtrppr](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/drtrppr/32/1763_2.png) [@drtrppr](https://discourse.cakephp.org/u/drtrppr)\
**Post date:** [May 12, 2020, 8:04pm UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/14 "2020-05-12T20:04:29Z")

</div>

Ah, after quick reading bake and cache pages in cookbook, didn’t have a clue yet 🙂

---

<div class="post-metadata">

**Author:** ![drtrppr](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/drtrppr/32/1763_2.png) [@drtrppr](https://discourse.cakephp.org/u/drtrppr)\
**Post date:** [May 15, 2020, 12:25pm UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/15 "2020-05-15T12:25:28Z")

</div>

Did have mixed results, sometimes I got the expected results, mostly not.

But it appears I was mixing things up. Baked specifiic model to change the display-field, sometimes followed by a ‘bake all’, and doing a cake cache clear\_all now and then.

Step by step doing things and looking to the code after everystep etc. it’s obvious what happens.

The ‘cake bake model Table --display-field ColumnName’ sets the display field. When not doing anything else, the view-page stays untouched. Off course you have to do a ‘cake bake template Table’, then the view page shows the desired column name instead of the default ‘id’. My misconception was that the template used some kind of variable to show the display-field, so when altering the model, that would be enough. So, looks like this is now clear to me, nothing unexpected here anymore.

---

<div class="post-metadata">

**Author:** ![drtrppr](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/drtrppr/32/1763_2.png) [@drtrppr](https://discourse.cakephp.org/u/drtrppr)\
**Post date:** [May 16, 2020, 8:44am UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/16 "2020-05-16T08:44:22Z")

</div>

So, now I’m back to the original post, with a little more knowledge, but still the same question.

When doing a ‘bake all --everything -f’ I expect bake to create a complete set of new MVC-files and templates based on the actual structure of the database.

When setting a different display-field instead of the default ‘id’, after the bake the display-field stays the non-default.

A cache could be the ‘problem’. Using the zuluru’s pointed to ‘cake cache clear\_all’ before doing the bake, should solve it. But it doesn’t.

What’s the next thing I have to do to get the wanted behaviour? Otherwise, is it a bug or is it intended behaviour? When it’s intended, what more changes will be persistent (where to find?)?

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [May 16, 2020, 4:29pm UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/17 "2020-05-16T16:29:13Z")

</div>

What do you mean by “setting a different display-field instead of the default ‘id’”? Is this something that you do after running the bake? If so, then you would need to re-bake anything (most specifically, templates) that’s affected by that change in order for it to take effect.

---

<div class="post-metadata">

**Author:** ![dreamingmind](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dreamingmind/32/1857_2.png) [@dreamingmind](https://discourse.cakephp.org/u/dreamingmind)\
**Post date:** [May 16, 2020, 7:11pm UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/18 "2020-05-16T19:11:35Z")

</div>

> [@drtrppr](#):
>
> When setting a different display-field instead of the default ‘id’,

id is not the default

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [May 16, 2020, 9:45pm UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/19 "2020-05-16T21:45:38Z")

</div>

> [@dreamingmind](#):
>
> id is not the default

I think it is sometimes, when it can’t find something it likes better?

---

<div class="post-metadata">

**Author:** ![drtrppr](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/drtrppr/32/1763_2.png) [@drtrppr](https://discourse.cakephp.org/u/drtrppr)\
**Post date:** [May 17, 2020, 7:05am UTC](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265/20 "2020-05-17T07:05:23Z")

</div>

Yes, as described in:

> [@drtrppr](#):
>
> you have to do a ‘cake bake template Table’, then the view page shows the desired column name instead of the default ‘id’. My misconception was that the template used some kind of variable to show the display-field

What I’m trying to do is to (re)build prototypes by using a batch file, so as a start:

- cake bake all --everything -f
- cake bake model Table --display-field column\_a
- cake bake template Table
- etc.

In this way I hope I can concentrate on getting the database right when building a prototype. After making some changes to the database, and maybe some changes to the batch, I can get a prototype up and running on the fly.

In order to get this 100% working, that first bake has to build new files, so that’s where’s my concern.

[Next page](https://discourse.cakephp.org/t/bake-not-generating-100-new-model-files/6265.md?page=2)
