Jump to content

Removing a field from database


Frank Vèssia
 Share

Recommended Posts

I need to remove a field from user template, the problem is I have more than 40.000 registered users and every time i tried to remove the field from the admin I got a sort of crash and the result is the field was not removed. Is there a way I can remove it manually directly from the database? Which tables I have to check? Thanks

Link to comment
Share on other sites

You can also remove the fields using the API.... Backup your site first, please! This was written in a function context so feel free to change it and use in a template file context. You could also wrap the code in a conditional if $user->isSuperuser... Changed and done...

if ($user->isSuperuser()) {
 
    //first remove the fields from 'user' template before deleting them.
    $t = $templates->get('user');
    $fg = $t->fieldgroup;
    $fg->remove($fields->get('your_field'));
    $fg->save();
 
    //delete the fields
    $f = $fields->get('your_field');
    $fields->delete($f);
 
}
Edited by kongondo
Changed code to template file context
  • Like 8
Link to comment
Share on other sites

So long as the field isn't a repeater, file/image, or PageTable, PW 2.5 (2.4 dev) can do it in one query, which should take about a second. PW 2.4 and prior cycled through each page to delete a field. So that could be a slow process, though it is a good process. PW 2.5 still has to cycle through every file/image or repeater/pagetable field since they all involve external assets that also need to be deleted. But if the field you need to delete isn't one of those, you may want to consider waiting for PW 2.5 since we may soft launch it as soon as next week. Or you could try out the dev branch locally to test things out and see if you want to use it live. 

  • Like 5
Link to comment
Share on other sites

yeah, i'm still using 2.3 for this project. It's quite risky to upgrade PW at this point (40k users, almost 3k logins per day), I made it in the past and I had some little problems, even during the night users are always connected doing stuff (it's a social network), moreover I made a big modification since I had the 32k files limit problem, solved with Wanze's solution ...but I need to change server very soon, maybe I can wait 2.5, copy the site to the new server, upgrade PW, reapply the mod and if everything looks ok switch dns...thanks anyway

Link to comment
Share on other sites

yeah, i'm still using 2.3 for this project. It's quite risky to upgrade PW at this point (40k users, almost 3k logins per day), I made it in the past and I had some little problems, even during the night users are always connected doing stuff (it's a social network), moreover I made a big modification since I had the 32k files limit problem, solved with Wanze's solution ...but I need to change server very soon, maybe I can wait 2.5, copy the site to the new server, upgrade PW, reapply the mod and if everything looks ok switch dns...thanks anyway

I believe Wanze's solution to the filesystem limit problem has been added to the dev core:

https://github.com/ryancramerdesign/ProcessWire/issues/432#issuecomment-40951719

  • Like 1
Link to comment
Share on other sites

yeah, i'm still using 2.3 for this project. It's quite risky to upgrade PW at this point (40k users, almost 3k logins per day), I made it in the past and I had some little problems, even during the night users are always connected doing stuff (it's a social network), moreover I made a big modification since I had the 32k files limit problem, solved with Wanze's solution ...but I need to change server very soon, maybe I can wait 2.5, copy the site to the new server, upgrade PW, reapply the mod and if everything looks ok switch dns...thanks anyway

This sounds like a good case study for PW...if you could do a write-up about creating a social network site with PW that would be great :-). Btw, when ready to migrate to 2.5, are you saying you couldn't even warn users in advance that the site will be offline for a set number of hours? 

  • Like 2
Link to comment
Share on other sites

Well, this social network is a result of more than 2 years of development (alone), I can write something about but I'm not a top level programmer :), I'm pretty sure a lot of stuff I created can be made in a better way.
I can stop the website few hours in the night...anyway I'm migrating to a better server so I will make all the test there and when ready move everything.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...