Populating Database Table with Default Keys
Permalink
Hello,
I have a plugin, it installs itself as a single page in the dashboard. The root of my package contains a db.xml file. In this file are the tables I would like set up, along with the default keys for each table.
2 years ago when I started this plugin, the table in the database would have the keys added during install.
But now, when I install my package, if I "select * from tableName" it returns as an empty set. The table is there, but the columns are not being added.
Do we have to manually create the table columns now? During install, my db.xml is not creating them as before.... Only the table is being made, but the columns are not being made.
I have a plugin, it installs itself as a single page in the dashboard. The root of my package contains a db.xml file. In this file are the tables I would like set up, along with the default keys for each table.
2 years ago when I started this plugin, the table in the database would have the keys added during install.
But now, when I install my package, if I "select * from tableName" it returns as an empty set. The table is there, but the columns are not being added.
Do we have to manually create the table columns now? During install, my db.xml is not creating them as before.... Only the table is being made, but the columns are not being made.
I might be misunderstanding, but I thought that 'select *' returning an empty set would indicate zero rows; not necessarily zero columns. Can you check the actual database structure using, eg, phpmyadmin?
Well I suppose you could be right. Either way I think I still need to insert a row of default values during install. But I understand now where I was mixed up thanks to your answer.
c5 doesn't insert a row of default values on install, but it still creates the columns.
I thought it was doing so before because I had added the row manually during development. But a ground up install of my plugin won't work unless I provide default values before the user gets to the page they are used on.
What really happened here is I have a block that pulls some settings from a root db.xml.
The root db.xml needs the values to get saved before the block asks for them.
During development, I was creating the settings page before calling for the data from the block. So the default values for my settings got inserted onto my site during development. And after I had added the settings manually I made a loop that checks for them. Since I'm coming back to finish this on a new c5 install, the settings didn't exist but the loop that checks for them still does.
So anyways now I'm just adding a row of defaults during install.
Thanks for helping me understand my own code! lol
c5 doesn't insert a row of default values on install, but it still creates the columns.
I thought it was doing so before because I had added the row manually during development. But a ground up install of my plugin won't work unless I provide default values before the user gets to the page they are used on.
What really happened here is I have a block that pulls some settings from a root db.xml.
The root db.xml needs the values to get saved before the block asks for them.
During development, I was creating the settings page before calling for the data from the block. So the default values for my settings got inserted onto my site during development. And after I had added the settings manually I made a loop that checks for them. Since I'm coming back to finish this on a new c5 install, the settings didn't exist but the loop that checks for them still does.
So anyways now I'm just adding a row of defaults during install.
Thanks for helping me understand my own code! lol
Now if I could only understand my own code... ;)