# MIGXdb Table Custom Prefix Not Used Properly?

**URL:** <https://community.modx.com/t/migxdb-table-custom-prefix-not-used-properly/1467>\
**Category:** Extras\
**Created:** [September 5, 2019, 9:20am UTC](https://community.modx.com/t/migxdb-table-custom-prefix-not-used-properly/1467 "2019-09-05T09:20:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![parthian](https://community.modx.com/letter_avatar_proxy/v4/letter/p/ad7895/32.png) [@parthian](https://community.modx.com/u/parthian)\
**Post date:** [September 5, 2019, 9:20am UTC](https://community.modx.com/t/migxdb-table-custom-prefix-not-used-properly/1467/1 "2019-09-05T09:20:52Z")

</div>

Modx 2.7.1 MIGX 2.12.0

Problem: Custom Prefix for Table is ignored. So a migxLoopCollection always fails until table is renamed via PHPMyAdmin to modx\_sometablename

Process  
Adding a Custom Table for some database activities.  
As is customary I thought I’d use a custom prefix, say, myprefix\_ so as to make it clear it isn’t a modx\_ table.

Went through the process in the MIGX Extra (shouldn’t this be called MIGXdb in the menu?)  
Package Name to Test  
set table-prefix for a custom prefix and entered a custom prefix e.g. myprefix\_

Create Package. Then root around in Filezilla finding  
~/core/components/Test/model/schemaTest.mysql.schema.xml

Contains:  
`<model package="Test" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" phpdoc-package="" phpdoc-subpackage="" version="1.1">`

But I think it should contain tablePrefix=“myprefix\_”

As there is no mention of a prefix all else goes wrong. parseSchema, CreateTables etc: their outputs have no mention of myprefix\_  
And of course migxLoopCollection fails - and silently. Tried everything to get it to work but in desperation renamed the table and jackpot - my handedited data appeared on my webpage from the custom database table.

I wonder if the few who use the MIGXdb never use the prefix? So it’s never been spotted.

A bug or have I missed something?

Stuart

---

<div class="post-metadata">

**Author:** ![parthian](https://community.modx.com/letter_avatar_proxy/v4/letter/p/ad7895/32.png) [@parthian](https://community.modx.com/u/parthian)\
**Post date:** [September 5, 2019, 9:25am UTC](https://community.modx.com/t/migxdb-table-custom-prefix-not-used-properly/1467/2 "2019-09-05T09:25:27Z")

</div>

Actually, just rememberd createTables did use the custom prefix field. Wished it hadn’t, would have saved a couple of hours of head bashing.

---

<div class="post-metadata">

**Author:** ![bruno17](https://community.modx.com/user_avatar/community.modx.com/bruno17/32/71_2.png) [@bruno17](https://community.modx.com/u/bruno17)\
**Post date:** [September 5, 2019, 10:07am UTC](https://community.modx.com/t/migxdb-table-custom-prefix-not-used-properly/1467/3 "2019-09-05T10:07:45Z")

</div>

I very seldom use custom prefixes.

But if you do so, you allways have to tell, that you do so, at all migxLoopCollection - calls or at the manager - actions

---

<div class="post-metadata">

**Author:** ![parthian](https://community.modx.com/letter_avatar_proxy/v4/letter/p/ad7895/32.png) [@parthian](https://community.modx.com/u/parthian)\
**Post date:** [September 5, 2019, 10:52am UTC](https://community.modx.com/t/migxdb-table-custom-prefix-not-used-properly/1467/4 "2019-09-05T10:52:31Z")

</div>

Thanks Bruno.

[[!migxLoopCollection?  
&packageName=`test`  
&classname=`Test`  
&prefix=`modx_`  
]]

&prefix did the trick - doesn’t seem to be documented. Suggests nobody uses custom prefix table names. Thought it would be the done thing. Hopefully this helps someone else.

Cheers

---

<div class="post-metadata">

**Author:** ![bruno17](https://community.modx.com/user_avatar/community.modx.com/bruno17/32/71_2.png) [@bruno17](https://community.modx.com/u/bruno17)\
**Post date:** [September 5, 2019, 11:17am UTC](https://community.modx.com/t/migxdb-table-custom-prefix-not-used-properly/1467/5 "2019-09-05T11:17:04Z")

</div>

when using the default prefix of your MODX - installation, by default modx\_ , you don’t need to specify that

---

<div class="post-metadata">

**Author:** ![markh](https://community.modx.com/user_avatar/community.modx.com/markh/32/36_2.png) [@markh](https://community.modx.com/u/markh)\
**Post date:** [September 5, 2019, 1:06pm UTC](https://community.modx.com/t/migxdb-table-custom-prefix-not-used-properly/1467/6 "2019-09-05T13:06:27Z")

</div>

I’d like to also recommend not to use custom prefixes. The `modx_` prefix is only a default, and the idea of prefixes is that you can have multiple MODX installations (or even different CMSes) in a single database table. By using a custom prefix, you remove that flexibility.

Instead, prefix the object tables with what you like. Maybe `<object class="Test" table="mycmp_test" extends="xPDOSimpleObject">...</object>`. It will then be created as `modx_mycmp_test` which is sufficiently prefixed to avoid conflicts, while keeping the flexibility of the MODX prefix.

---

<div class="post-metadata">

**Author:** ![parthian](https://community.modx.com/letter_avatar_proxy/v4/letter/p/ad7895/32.png) [@parthian](https://community.modx.com/u/parthian)\
**Post date:** [September 5, 2019, 1:24pm UTC](https://community.modx.com/t/migxdb-table-custom-prefix-not-used-properly/1467/7 "2019-09-05T13:24:40Z")

</div>

Indeed, its just a cutnpaste from my test to ensure &prefix worked with my renamed table.

---

<div class="post-metadata">

**Author:** ![parthian](https://community.modx.com/letter_avatar_proxy/v4/letter/p/ad7895/32.png) [@parthian](https://community.modx.com/u/parthian)\
**Post date:** [September 5, 2019, 1:42pm UTC](https://community.modx.com/t/migxdb-table-custom-prefix-not-used-properly/1467/8 "2019-09-05T13:42:29Z")

</div>

I see @markh - in other words keep the custom table associated with that installation of modx (as opposed to something else in the database).  
I’m building a Weather History application. Taking 20 years or so of DarkskyAPI wind direction, speed and gusts etc for my town and storing them in a database. Which could be 7300 rows. Then use chartjs or d3 or something to plot a radar chart of winddirection and speed for e.g. Every July since 2000. Just for fun and to practice MIGx and XPDO and charting.

And probably not a big deal but was thinking that with a different prefix it would be easier to only backup my modx\_ tables and not always backup my weather data. I’ve just found backupMODx (where has that been all my life). Not sure if it ignores non modx\_ tables.  
And I’m too scared to try the different database approach.  
I’ll figure something out.

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://community.modx.com/user_avatar/community.modx.com/system/32/2_2.png) [@system](https://community.modx.com/u/system)\
**Post date:** [September 7, 2019, 1:42pm UTC](https://community.modx.com/t/migxdb-table-custom-prefix-not-used-properly/1467/9 "2019-09-07T13:42:31Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
