Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Install new Modul with Database tables comes this message.
DatabaseSchemaObjectExistsException: Table xxxxx already exists. in DatabaseSchema->createTable() (line 623 of http://xxx\xxx\xxx\xxx\includes\database\schema.inc).
But this tables doesnt already exists.
Greets Lennard
Comments
Comment #1
Damien Tournoud CreditAttribution: Damien Tournoud commentedThat probably means that your module is incorrectly calling drupal_install_schema() in its hook_install(). This is not necessary anymore as Drupal is calling this for you automatically.
Comment #2
Lennard CreditAttribution: Lennard commentedThanks i haved see it. Now is the Install hook out and the error is gone.
Comment #3
David_Rothstein CreditAttribution: David_Rothstein commentedComment #5
calbert CreditAttribution: calbert commentedCould you explain how I would remove this to fix the problem?
Comment #6
David_Rothstein CreditAttribution: David_Rothstein commented@calbert: File a bug report against the module that is causing the problem (whichever module's tables are being installed when this message appears).
Comment #7
christophebst34 CreditAttribution: christophebst34 commentedThat issue comes from the old implementation of hook_install ()
Apparently it is not required anymonre, according to Drupal. But many tutorials and books are still using it for Drupal 7....
Here is an example of a proper implementation :
Hope it will help...
Comment #8
David_Rothstein CreditAttribution: David_Rothstein commentedThe hook_uninstall() implementation in the above example is actually also unnecessary. All you need is hook_schema()... everything else is taken care of automatically by Drupal. See http://drupal.org/node/224333#install-schema
Comment #9
christophebst34 CreditAttribution: christophebst34 commentedYep.. Not necessary anymore. This is correct.
But if left it does not trigger an error...
BTW, absolutely not required in Drupal7.
Chris
Comment #10
calefilm CreditAttribution: calefilm commentedI'm really sorry to take this issue backward... I'm just so confused. I'm not very experienced at Drupal. I can enable, disable a module, put a site online, install patches, etc etc,, the basic stuff but when you get technical and start talking 'hooks' I'm just not there yet.
The reason why I'm here is I was referenced this post after responding to a similar thread here: http://drupal.org/node/1265322
It seems i get a message like this if I enable a particular module:
DatabaseSchemaObjectExistsException: Table <em class="placeholder">comment</em> already exists. in DatabaseSchema->createTable() (line 652 of /Users/cale/Sites/acquia-drupal/includes/database/schema.inc).
Is this because my comments table still exists in my database, which it does? If I disable it I cannot uninstall it, even if I have comments in the database. . . This has happened before with other modules.
So my question is, does my issue pertain to the link you have provided to the Hook install? If so, can someone explain... since I can't grasp how to do a hook... am I okay moving forward with building my site or will this issue come back to haunt me?
Comment #11
mark@redhorseinteractive.com CreditAttribution: mark@redhorseinteractive.com commentedHi, How do you change the hook install... I'm getting a problem something like this, if not exactly.
Comment #12
mark@redhorseinteractive.com CreditAttribution: mark@redhorseinteractive.com commentedYes, I'm having the same problem... c'mon guys give us a easy answer not one we have to figure out... I know figuring stuff out is one of the 'joys of Drupal' but there's only so much time in a day, huh? Please! How do we get this hook thing out of the way. Every module I load is throwing an error (after I restored database, by the way)... who knows what else is screwing up... I was getting really excited with Drupal 7 for a bit there but working with it is still like walking on glass!
Comment #13
pxljedi CreditAttribution: pxljedi commentedI'm new to Drupal too and I'm receiving this error. I don't understand how to fix the "hook".
Comment #14
interlated CreditAttribution: interlated commented@pkljedi - you need to search your whole system for a .install file that specifies the schema for the database table.
e.g. it says "Table ognotify_attending" missing you need to search for "ognotify_attending"
A .install file should come up (e.g. ognotify.install using my example)
The most likely fix is that there is no 'drupal_uninstall_schema'. This is assuming the module is being enabled a second time. If you have 2 modules that create the same schema you are in trouble.
function ognotify_uninstall() {
drupal_uninstall_schema('ognotify_attending ');
}
Replace 'ognotify_' to the name of the module and 'ognotify_attending' to the name of the table that you searched for at the beginning.
Add an updated version of the above code. Disable, clear caches,uninstall/install the module.
It is a 'bug' in the module - so raise an 'issue' against the module.
I actually had to put the code in:
function ognotify_disable() {
drupal_uninstall_schema('ognotify_attending ');
}
as the module has sub-module dependencies. This would remove data during disable, so probably not appropriate to leave there.
Probably easier to delete the database table using sql and just raise a bug. I often also find that a refresh of the 'white screen' does what I wanted it to do.
John
Comment #15
David_Rothstein CreditAttribution: David_Rothstein commented#14, that's actually not correct.
As stated above, in Drupal 7 modules should not be calling drupal_uninstall_schema() during uninstall themselves, since Drupal does it automatically. (It's harmless if they do call it, but it won't fix anything either, so you shouldn't file a bug report suggesting that they need to do it.)
As far as I know there are really only two possible causes here:
(with the actual name of the module replaced), that's a critical bug which would cause this, and you should file a bug report against the module to remove this code.
However, these days, this kind of bug is pretty unlikely to come across, since it's totally impossible to install a module in Drupal 7 that has this code so it probably would have been fixed already, and certainly fixed already for any module that is remotely ready for use on a production website.
As long as you don't have any important data stored in that module (because the procedure here will destroy it), the thing to do here is probably to temporarily fool Drupal into thinking the module is installed, so it can be uninstalled and then reinstalled again, basically something like:
UPDATE system SET status = 0, schema_version = 0 WHERE type = 'module' AND name = 'MODULENAME';
(again using the actual name of the module).
This isn't guaranteed to work as it probably depends on the specific way in which your site broke, but that can't really be dealt with in a generic issue like this one. It should also be something that very few people ever run into. (See also #1551132: When trying to create a table that already exists but is empty, recreate the table rather than throwing a DatabaseSchemaObjectExistsException which proposes making some changes so that in the unlikely event you do run into it, Drupal can more gracefully recover without the need for the manual database query described above.)
Comment #17
interlated CreditAttribution: interlated commentedDavid. The 2nd one then. There was no drupal_install_schema in my example. I got uninstall from #7 as you corrected previously.
Therefore, the only answer is to drop the table using SQL (which I had to do). It is also indeterminate how the problem occurred in the first place. Probably some other bug stopped the module install process. I expected 'uninstalling' the module to get rid of the table but it does not.
Comment #18
tbrowninfinitymark CreditAttribution: tbrowninfinitymark commentedI am having the same issue with OG on a new D7 site I just built last weekend. I don't get any of these errors until I enable OG - then I get them all over the place.
I have tried restoring site files and db to no avail. Anyone able to resolve this yet?
Comment #19
tbrowninfinitymark CreditAttribution: tbrowninfinitymark commentedMy issue was happening when attempting to make a content type a group type. I just dropped the tables it was complaining about (field_group_group and field_revision_group_group) and saved the content type successfully. Then I experienced a similar issue when attempting to make an existing content type a group post type - I again dropped the tables being complained about (field_group_audience and field_revision_group_audience) and was able to save it successfully.
Comment #21
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedGiven what was said above, should this line be in modules/system/system.install?
drupal_install_schema('system');
Comment #22
SunRhythms CreditAttribution: SunRhythms commentedAnother work around....
The Table is the actual Table in the database. It basically means there is a mismatch in data from your original database file and the one you currently have, but unfortunately it can't overwrite it. You have to actually uninstall the module and all of its required modules, fields, and other components and then delete the table item out of the MySql database then reinstall the module if you need it (unless you know how to rewrite the sql table information that is needed yourself, I'm assuming)...
Comment #23
capysara CreditAttribution: capysara commentedThis issue is old, but still the first result in a search. My issue was custom modules/features being enabled/disabled at some point. I ran drush rr a few times and that cleared everything up.