Why do we have this exception? (and in general why does D7 have so much worse handling of things like this??)
the error comes when a user tries to install a module which was previously installed and the .instal chokes simply because the table was already there.. and worse, it kills the process of enabling all the other modules that were trying to be enabled.
pretty sure in D6 we'd just skip this.. why does everything in D7 cause a stupid exception and just bail with a stupid message: "The website encountered an unexpected error. Please try again later. " really? try again later? why? is this magically going to fix itself?
what are we trying to avoid here?
- could the existing tables possibly be of an old design and therefore we would need to run updates on them? but can't db code see this and run the updates; most likely the system table entry is still there so we do know what version of schema exists?
- are we trying to force module designers to write code in all .installs to first check if tables exist and then handle this in the .install file? why would we want to replicate this code 200 times on a project?? why not have db code handle this?
really tired of seeing these exceptions all the time for no apparently useful reason.
| Comment | File | Size | Author |
|---|---|---|---|
| #124 | interdiff_120-124.txt | 839 bytes | ravi.shankar |
| #124 | 1551132-124.patch | 970 bytes | ravi.shankar |
| #120 | drupal9_schema_create_table-1551132-120.patch | 988 bytes | weekbeforenext |
| #118 | drupal-1551132-113.patch | 1010 bytes | tim-diels |
| #115 | drupal_install_schema_shared_tables-drupal8-1551132-115.patch | 644 bytes | tomefa |
Comments
Comment #1
catchThis isn't a major bug at all, if you install a module, remove it then install it again without uninstalling then that's not going to work.
The exceptions are largely because we switched to PDO. Probably we could handle them better to give a more useful message.
Comment #2
liquidcms commentedyes.. big improvement moving to PDO.. except that usability of Drupal took a huge hit. a better msg isn't the answer here (although that one is not only misleading and incorrect; but annoying.. lol).. i had panels/ctools tables already in place; 1/2 the modules in that set didnt have uninstalls.. my process was:
D7:
- enable 6 modules in ctools/panels set
- get single pdo exception
- resubmit module page with ALL disabled since i have no idea the mess created with partial install as i have no idea what has actually been done before it pdo's
- manually go through mysql interface and remove single table.
- repeat this 5 or more times to find out each table involved
D6:
- enable 6 modules in ctools/panels set
How is D7 better? Is it not possible to ignore exceptions? is there no way PDO can just flag "error" (this really shouldn't be considered an error; a warning at best). I don't know PDO but the PHP debugger i use halts on PDO exception and asks if i want to ignore this type of msg in the future.. hmm...
Comment #3
David_Rothstein commentedWhat are the specific steps to reproduce this bug? I've never seen this, and I am able to install all Ctools/Panels modules in D7 with no problem.
It might be possible to make module_enable() clean up after itself better in the case of a catastrophic failure, but we'd need to understand exactly what the failure is first.
I definitely don't think it makes sense to blindly plow ahead and assume everything is OK, though. If you try to create something that already exists, that needs to stop the process (of installing the module in question as well as any modules that depend on it) because you have no idea what the state of the database actually is at that point. Otherwise you risk a site where everything "looks good" but is actually broken underneath, and that would lead to impossible-to-debug problems later on.
The only way Drupal tries to install a module is if the schema version is -1 (indicating that the system believes it to be uninstalled). So I think that means the "actual" schema version would not be available in this case.
Not sure what you mean; Drupal 7 already does handle this. Module authors no longer install their own database tables at all (see http://drupal.org/node/224333#install-schema) so there's no check they need to perform either.
In fact, one way I know you can get the DatabaseSchemaObjectExistsException would be a module that isn't properly updated to D7 and is still trying to install its own schema. But that will fail every time, so it doesn't sound like the case here.
Comment #4
liquidcms commented- ctools/panel tables already existed. can't state for sure how that came about; possibly i cloned an existing "starter" db but then system table would have been cloned as well.
- modules were disabled (meaning they were enabled at some point since the tables existed but now weren't; possibly i manually went in to system table and set status to 0 to repair a WSOD (likely due to issues with entities))
so that's the starting point; try to enable module; pdo exception.
so yes, possibly (although not sure that's how i got to this point) some manually messing with the db.
so i guess the question becomes this:
is that the best answer? in my case; and i suspect most cases, the tables are fine... so is it better to "plow ahead" when in fact there is nothing wrong or to bail in the middle with no indication of what had been completed in the install process; and in fact some of the modules are left with status = 1; although we have no idea that they were installed properly.
possibly a better approach (although maybe not possible with PDO) would be to simply assume if a table is there it is likely ok (since it pretty much always will be) and then issue warnings that the module install was successful but that the tables already existed and therefore were not re-created; and that proper functional operation should be verified or possibly uninstall the module and reinstall - assuming of course that an uninstall would clean up tables (which i dont think it currently does - didn't help in this case).
- no, this is not the case here.
Comment #5
David_Rothstein commentedUninstall normally should fix this, but the problem might have been that Drupal believed the module to be already uninstalled.
I don't like the idea of leaving the modules enabled, but it would be nice here to catch the exception, bail out with a friendly message, and tell people that there's leftover data from an older version of the module and give them a chance to uninstall it. Possibly this could be achieved with a different module status that means "broken" (i.e., -2 for the schema version rather than -1, or something like that), which would allow you to go to the uninstall page and at least run some kind of limited uninstallation from there that cleared out the module's database tables.
Comment #6
shamar commentedI try in .install file in fuction hook_install in function
drupal_install_schema('module');
to write
drupal_install_schema('name of table');
, where 'name of table' in 'schema'
In result:
function module_install() {
drupal_install_schema('name of table');
}
And module start to work, and table was created.
Comment #7
liquidcms commentedsorry.. i am coming back to this as i think this is a huge loss of usability for D7.
my current case that is showing this is core based modules.
i am trying to enable the Statistics module and i get this error:
so those doing core code would state: "why does that table exist?" my reply would be who cares? the fact is the table is there and as far as i can tell the only way to fix the issue is to go into db directly and delete the table; not too big a deal for some people with access; but harder if they don't and much harder for modules with numerous tables.
there is no way through the UI to fix this situation. we can't even uninstall the module and have it clean this up.
and even worse, when i go to the module list page the module is listed now as enabled; but it really isn't (how is that possible?) but i need to uncheck it and submit to have it show correctly.
again, i am hard pressed to see why a better solution if a table exists would be to not simply go "ok, cool, our table is already there" and then just continue on our merry way. YES, i understand the 5% case where the table that is there is the wrong version; but why not just a msg saying "the table we tried to install was already there so not sure of validity" or better yet; check existing table against schema for the module. either way this certainly must be a better solution than making the module no longer installable.
Comment #8
liquidcms commentedand just to further iterate how much of a pita this is, this is what i had to do to enable the core Statistics module:
- enable stats module
- fails with msg above; but shows on module list as enabled (but isn't)
- uncheck module and re-submit
- go to db directly and delete accesslog module
- re-enable stats module
- new error msg stating node_counter table exists
- stats shows as enabled but isn't
- uncheck stats again and submit
- delete node_counter table
- re-enable stats
- again get error stating accesslog table is there since it was created prior to bailing due to node_counter table existing
- again, resubmit with stats disabled
- delete both tables
- re-enable
YAY.. success.. and WOW.. holy crap batman!!
and for the record; both tables that were initially there were both empty and both had correct schema
i have done a ton of sites since D4 days and never had this much frustration simply enabling a module.. ok, maybe in D4 days, but too long ago to recall..
Comment #9
henrikakselsen commentedI just want to chime in to agree with liquidcms here, as I have experienced a lot of this stuff myself and really having difficulties understanding what the rationale is behind giving a cryptic error message instead of giving the user a choice to try to enable the module anyway.
I have fixed my issues by just going into the db and manually deleting the database tables for the module myself, but that should really not be necessary and is bad usability in my opinion.
Comment #10
damien tournoud commentedThis is just a case of "garbage in, garbage out". If you have a database in a weird state, weird things are going to happen. Simply ignoring the garbage (the table already exists, while it should not be here) is only going to make it worse down the line, as weird errors are going to pop-up if the schema of the table is not correct.
The only thing we could do is try to catch this early, and ask the user for the permission to drop and recreate the table (we cannot keep its data, as it is guaranteed to be stale).
Let's study this for 8.x. I'm requalifying this as a feature request because there is no bug here.
Comment #11
liquidcms commentedto those developers stumbling upon this and tired of dealing with this, i simply commented out this line:
throw new DatabaseSchemaObjectExistsException(t('Table %name already exists.', array('%name' => $name)));in /includes/database/schema.inc in the createTable function.
(actually i replaced it with a msg telling me table already existed and which table.)
Comment #12
spyckedelic commentedI am encountering the same issue
I restored a back up using the "restore and back up" module.
Then I wanted to reenable the internalization module,
but it gives me this error:
"DatabaseSchemaObjectExistsException: Table i18n_string already exists. in DatabaseSchema->createTable() (line 657 of /home/kathrins/public_html/includes/database/schema.inc)."
I understand the table already exists, which makes sense, but I can't seem to get rid of it.
I tried disenabling, uninstalling, clearing caches and reenabling,
but it continues to show this error.
I also tried @liquidcms' suggestion to comment out the following
throw new DatabaseSchemaObjectExistsException(t('Table %name already exists.', array('%name' => $name)));
in /includes/database/schema.inc in the createTable function.
but this doesn't seem the work either ...
Comment #13
Anonymous (not verified) commentedNot sure if this the right place, but I get this error with Panels. I did some stupid things with Panels and restored from a backup that was prior to installing Panels. Now I cannot seem to get rid of the error no matter what I do.
I have read several threads and my questions is, could I just do the following to remedy the situation (without breaking anything more):
Delete the files at /sites/all/modules/panels
Drop the tables panels_display, panels_layout, panels_mini, panels_node, panels_pane, panels_rendered_pipeline
Reinstall Panels
?
In other words, is there relevant info about Panels somewhere else?
Comment #14
mgiffordI got this while flushing cache on a D7 instance.
Comment #15
frank ralf commentedSame here when flushing the cache or trying to run update.php on a D7 installation:
I also cannot access
admin/structure/featuresand/admin/modules.Looked through some of the other related issues and this seems to happen with all kind of modules (core and contributed).
EDIT
Only after deactivating Features using Drush I could get the site working again. So #1272264: Rebuilding features causes FieldException if module is not available might be the right place to follow this issue.
Comment #16
Angelluc commentedHi Liquidcms as it better not only to throw out that line, can you give the code for the msg telling the table already existed and which table? and where you put this code? Than at least I can handle it.
Comment #17
liquidcms commentedin includes/database/schema.inc i replaced this function with:
Comment #18
Angelluc commentedThx!
Comment #19
kristen polI'm getting this quite a bit too while working with features. I don't know why it should complain if you ask it to create a table that already exists. It should be happy it doesn't have to create the table :P
Comment #20
mexicoder commentedStumbling across this issue quite a lot when using features. Although this doesn't address the core issue, one of the main reasons was that I was using the backup and migrate module to pull the latest version of the production database down to my local development version. When you use the restore function on the backup and migrate module you can be left with a lot of mess in your database as it doesn't drop all tables hence the frequency of seeing this error message. (Would still like to see an elegant solution for the exception issue though!)
Comment #21
kytom commentedI too had this issue when trying to revert features. #20 worked, thanks! Wipe clean the old database before restoring and everything works.
Comment #22
kristen polI made a patch for core like #17 and have it in my project's patches directory along with all my contrib patches. This issue happens so much with features for us that it's the only sane way for us to proceed.
Comment #23
liquidcms commentedyup, i only have 2 core hacks we do on every project we do: this one and the one to add style summary: http://screencast.com/t/QDMddmtK
although i guess you could almost call my rewrite of the admin_role module a big core hack since it is only fixing the busted idea of admin role that made it in to D7 core.
Comment #24
manuelBS commentedI also experienced that #20 helps lots of times
Comment #24.0
manuelBS commentedtypo
Comment #25
joyseeker commentedThank you #17 for posting the solution. I love the solution's elegance.
I'm getting this error a lot when I import a database into a new subdomain in my multisite set up. I'm not sure if multisite will still be an option in D8, but if it is, we who use D7 multisites restore a lot of databases from one subdomain into another, and this error and PDO exception errors are common. Drupal is assuming we don't know what we're doing, but we are doing what we need to.
Comment #26
jakerogers commentedliquidcms, Thanks for that...I've been struggling with this for Weeks and the solution lies in an obscure reply. I wonder how many others have had this same problem but overlooked this solution in #17. You should be running this show! I repeat my suggestion to Drupal.org administrators/Moderators...EVERY problem topic should require that Moderator post a "Solution" at the TOP of the node, so users will not have to wade through the mire of repeats and unproven suggestions, etc, etc.
I nominate liquidcms for President of Drupal.org...many thanks for your SOLUTION!
Comment #27
ibevamp commentedThanks #17 worked for me as well.
Just curious, shouldn't a check like this be standard? Meaning, shouldn't we submit this patch to be part of core?
Comment #28
jakerogers commentedI would certainly think so, but there seems to be some "political" interests at play here at Drupal.org. Not sure about that, but it seems to me that many here would rather see their names in print, dragging out solutions to generate more dialogue; rather than solving problems for the DrupalUser.
Comment #29
vm commentedComment #30
vm commentedreplacing issue summary from #26 which seems to have been made to correct a sentence in the original posters report.
Comment #31
mexicoder commentedThe reason #17 will not make it into core is that it is a workaround rather than a true fix. The reason the thread is still open is that it still needs work, the workaround couldn't go into core because of the possibility of unexpected behaviour or results which can be a nightmare for debugging and very confusing for new users (and experienced ones too). Drupal is throwing an exception because something exists which it doesn't have the capability of handling yet which is the safest thing to do. Yes it is a PITA, yes it needs more work and yes you can use workarounds like the one @liquidcms has been good enough to post up but understand the impact of what you are doing.
@JakeRogers sorry to disappoint you but there is no Dr Evil in charge - if there was I would have liked to shout at him too a few times, it is just regular users giving up time and contributing which anyone can do, the best advice if you don't like things the way they are is to get involved yourself.
Comment #32
dave reidThis error is easily re-producible if you have a multisite installation with shared core tables. You cannot install the second of the multisite sites because those core tables already exist, and drupal_install_schema() fails. Here's a patch against Drupal 7 core that works for us right now.
Comment #33
mgiffordComment #35
mgiffordsorry, for d7 testing.. I needed to switch versions. I'll switch it back when it's completed.
Comment #36
mgiffordUntested, but it should work as well in D8.
Comment #37
liquidcms commentedyes, simpler patch than mine indeed. i prefer mine though.
seems wrong to ever "fail" silently. the original designers of this exception were not completely wrong... having a remnant table in place when you install a module could actually be bad. i think a msg stating that the table already existed gives the user a little warning that something was there before but that it might not be the correct schema and they should either understand what they were doing that led them there or that it might not be a bad idea to check it out.
Comment #38
mgiffordComment #39
mgifford32: 1551132-drupal-install-schema-shared-tables-D7.patch queued for re-testing.
Comment #40
mgiffordNow the D7 version has passed, moving this back to D8.
Comment #41
mgiffordWhere is your patch Peter? I agree that having some sort of message would be better. Something like this perhaps?
Comment #42
liquidcms commentedthe code is posted in #17 above.. but patch attached
Comment #43
mgiffordComment #45
mgifford42: schema-table_exists.patch queued for re-testing.
Comment #47
mgiffordI don't know why you commented out the
throw new DatabaseSchemaObjectExistsExceptionline, but that certainly can't go into Core that way. I've rewritten it so that that line is uncommented but that there is a return afterwards. If not it just needs to be removed.Comment #48
mgiffordNow for @liquidcms solution (more or less) in D8.
Comment #49
dave reidI still think that's too high up for this fix and the Schema object shouldn't do this kind of logic. It should be in db_create_table().
Comment #50
liquidcms commentedYup, i'd agree with Dave.. except this was specifically for module install (original issue) but table_create can occur at any point. Existence check makes sense for all cases but possibly different message or action depending on what is trying to create it.
I guess we have no way to tell schema of a table.. which is too bad since we could check against install and if its an old table could just do the update to the latest or at least report it. Of course none of that makes sense if something else is simply creating a table (but this is likely rare that something other than a .install is creating tables (??)).
So i'd vote for Dave's idea of just including this in the table_create function; but including a message stating which table.
Mike, i must not understand what the thrown exception is doing. I was under the impression that was what halts execution and spits out exception error page.
Comment #51
mgiffordOk, so this just adds an else with
drupal_set_message(t('Table %name already exists.', array('%name' => $name)));if the table already exists.Comment #52
liquidcms commentedlooks good.
Comment #53
mexicoder commentedActually I think we are still some way off something that is suitable for core, remember we have to cater for all levels of users. If we simply use drupal_set_message, watchdog etc. there are going to be a lot of users who think- 'well I don't know what the message is telling me (in terms of impact on my site), but hey everything looks like it is still working' and carry on as normal but they'd not have the result they were expecting. The reason we were originally throwing an exception is that we are unable to perform the operation we are attempting. I think we may still need to throw an exception but give a more meaningful message that would allow users to actually fix their issue.
Comment #54
liquidcms commentedthe original issue was that in many (most) cases there is no issue.. and the exception is what causes the issues by breaking out of the install before it has completed and in an indeterminate state (with a really stupid and annoying msg).
i do agree more info would be useful.. as i mentioned above it would be nice to state something like which schema was found (and if not current; even run updates to bring it up to correct version).. but this would rely on the system record still existing (which might be the typical case).
so maybe this:
if table exists
- check if system entry is there
- - and fix or at least state schema mismatch if there is one
- - if schema is current do nothing
- if entry isn't there delete the table and then continue with the install process (including installing that table)
Comment #55
bleen commentedYes! ++
(though I wouldn't attempt to fix the schema mismatch, I would just give the error message. At that point there is a mismatch you may have data issues as well and that could get messy fast)
Comment #56
mexicoder commentedThink that this is still too tied to module install, esp if we are talking about the table_create function. We may be in danger of trying to do too much here. On a code and db level should we be surprised if we try to create a table that already exists and it fails? And should we be writing code to cater for this event? If we do need to write code we should maybe focus on the situations where we are genuinely performing the correct action, (I'd guess in the majority of cases this is not the case i.e. we have junk in our db, or we have done something weird) and not try to cater for this in core functions like table_create.
Comment #57
mariano.barcia commentedSubscribing. This issue is currently disrupting our site installs.
Comment #58
webservant316 commentedIf I enable 'comment' I get a scheme error. The module appears to be enabled, but then if I disable it, I cannot uninstall the module in order to clean things up. I am stuck.
Comment #59
webservant316 commentedOk - my saga for anyone that might need help or can help further.... as stated just above my 'comment' module got into a state where I could not enable it, but neither could I uninstall it, or at least it was not listed on the uninstall page. #17 above PLUS watching the database for 'field_deleted_data_###' already exists during the uninstall was the solution for me. My database had stray 'field_deleted_data_###' tables laying around. I think these tables are supposed to be removed on cron, but there they were. The problem they create is that when I tried to uninstall 'comment' the uninstall failed because of 'field_deleted_data_###' already exists. Here are the steps to curing my problem. I went through the enable, disable, uninstall 2x with the patch installed, then again without the patch installed to insure everything was operating smoothly again.
1. Run cron
2. REMOVE ANY STRAY 'field_deleted_data_###' TABLES
3. Install patch #17 above
4. Enable the 'comment' module
5. Disable the 'comment' module
6. Uninstall 'comment' module
7. RUN CRON TO REMOVE 'field_deleted_data_###' TABLES
8. Success! Continue...
9. Repeat steps 4-8 one more time. Success! Continue...
10. Remove patch #17
11. Repeat steps 4-8, Success!
In my case I think that early on in my website development I had enabled, then disabled the 'comment' module and then when I went to uninstall the 'comment' module it failed because a 'field_deleted_data_###' table already existed. There could be a serious Drupal bug here if either 1) cron is required to run in order to remove these temporary tables before another uninstall is attempted or 2) there is a race condition on the ### numbering algorithm. Anyway, in my case the uninstall of 'comment' failed, but it was removed from the uninstall list and so I forgot about it until now. Recently I needed to install the 'watcher' module but could not because I was unable to enable the 'comment' module because it was left in an inconsistent state.
My recommendations:
1. A Drupal guru might be advised to look into the bolded theory above.
2. Some smart logic such as #54 above could be very helpful.
3. Perhaps introduce an intermediate page that asks for permission to continue if problems are noticed.
Ok hope this helps, Jeff
Comment #60
webservant316 commentedAlso something MUST be done to fix this because when the 'table already exists' error happens as it inevitably will, the current 'throw error' can make things worse with in the database.
Comment #61
davidneedhamLots of weird stuff happening with this.
I'm not really sure how that's possible given the circumstances of this error. I clear the cache regularly. The modules do eventually become enabled through attempting to enable multiple times.
Comment #62
openmode commentedadmin/structure/content_migrate
Changed field type: The 'field_foto' field type will be changed from 'filefield' to 'image'.
Error message
Error creating field field_foto
exception 'DatabaseSchemaObjectExistsException' with message 'Table field_data_field_foto already exists.' in includes/database/schema.inc:657 Stack trace:
#0 /includes/database/database.inc(2720): DatabaseSchema->createTable('field_data_fiel...', Array)
#1 modules/field/modules/field_sql_storage/field_sql_storage.module(259): db_create_table('field_data_fiel...', Array)
#2 [internal function]: field_sql_storage_field_storage_create_field(Array) #3 /includes/module.inc(866): call_user_func_array('field_sql_stora...', Array)
#4 modules/field/field.crud.inc(180): module_invoke('field_sql_stora...', 'field_storage_c...', Array)
#5 sites/all/modules/cck/modules/content_migrate/includes/content_migrate.admin.inc(246): field_create_field(Array)
#6 [internal function]: _content_migrate_batch_process_create_fields('field_foto', Array)
#7 /includes/batch.inc(284): call_user_func_array('_content_migrat...', Array)
#8 /includes/batch.inc(161): _batch_process()
#9 /includes/batch.inc(80): _batch_do()
#10 /modules/system/system.admin.inc(2379): _batch_page()
#11 [internal function]: system_batch_page()
#12 includes/menu.inc(517): call_user_func_array('system_batch_pa...', Array)
#13 index.php(21): menu_execute_active_handler()
#14 {main}
Comment #63
jhodgdonUm. We should not move this to a different project until the Drupal Core issue is resolved? If you need an issue for a different project, please file a different issue... or else explain why it should not be a Drupal Core issue any more.
Comment #64
daffie commentedThe current version of 8.0.x-dev already checks if the table exists before creating it.
Comment #65
jhodgdonWell the bug most likely still exists in 7.x.
Comment #66
Media Crumb commentedIn deed it does and happens regularly with Features Modules because of cache clearing. Which patch is deemed the best to use for now on D7?
Comment #67
scorchio commentedI've got this when I've tried to upgrade a D6 site to D7. The site had a custom module (that I had to port to D7) with a custom database table. Now when I've tried to enable the module, the install has failed because the database table was there already. I could only enable the module with temporarily commenting out the table definition in hook_schema(). (By the way, similar things happen if you try to use a db_add_field() in hook_install() for adding a field which already exists.)
Comment #68
David_Rothstein commentedLooking at drupal_install_schema() I don't see where it does that at all.
And certainly if I test manually by adding
drupal_install_schema('forum')to the Forum module's hook_install() implementation in Drupal 8, everything explodes with aDrupal\Core\Database\SchemaObjectExistsExceptionwhen I try to enable the module.Comment #69
markabur commentedHere's the D7 version of #51.
My database got into a state where field_data_field_whatever already exists, but the field wasn't listed on the manage fields form, and there was an error when I tried to create the field as new. With the patch applied I'm able to create the field anyway.
Comment #72
pieterdcThe Drupal 7 patch failed testing because it tries to apply it against Drupal 8.
I updated the Drupal 7 patch file name so it puts the comment number before the Drupal version, according to https://www.drupal.org/patch/submit
Comment #74
pieterdcApparently the naming isn't enough to make it run against Drupal 7. Maybe the version of this ticket needs to change. I'm not going to fiddle with that.
About the patch itself; I would not accept it because it introduces an inconsistency with the rest of the methods in that file because it does not throw an error.
I would rather provide a new method createTableIfNotExists() that creates a table, unless it already exists, but doesn't throw an exception or logs a message is a table already existed. But then, what code is going to call that new method? Just thinking out loud.
Besides, I'm also having a look at #1343330: Field creation error needs correct cleanup which suggests a different approach.
Comment #75
cilefen commented@PieterDC You can change the issue version and post a patch with status "Needs review" then change the issue version back.
Comment #76
cilefen commentedOh, and there are some "testing only -- ignore issues" around you can use to simply post a patch for testing.
Comment #77
frank hh-germany commented#47
Fail on Commerce Kickstart 2.33 on New Install
Comment #78
frank hh-germany commentedI think, this is a great bug that comes with a security update on the core.
In old version on my sites, i have no problems.
In versions greater then 7.41 or near earlier ther was no problems with Commerce Kickstart.
But the older versions of the Core and some modules are no php7 compatible.
Php7 is the next great perfomancestep in the buildfuture.
Builders, please consider that.
I'm working on an adaptation of the CK-style from OT5 to AT Commerce.
But i use for this the "costum css tool" > I dont like change the original corefiles... > Hackatacks on WP in the year 13, 14 and 15 in the german Help-Forum Webmasterzentrale by google...
Comment #80
mikemadison commentedThe patch in #72 seems to resolve this problem on D7 for me.
Comment #81
albionbrown commentedLiquidCMS' comment #11 did the trick for me.
Encountered this issue when reverting features after a git branch checkout. Commented out the line
throw new DatabaseSchemaObjectExistsException(t('Table @name already exists.', array('@name' => $name)));, reverted features and finally uncommented the line again.Comment #82
polPatch #72 did worked for me too. Thanks!
Comment #84
aether commentedConfirming patch #72 fixed D7 issue for me as well.
Comment #85
johns996 commented#72 solved my perpetual errors from features that have been copied between servers. hopefully this gets into core soon.
Comment #86
travisc commented#72 works great, let's get this committed in 7.53
Comment #87
pieterdcAs said in #1551132-74: When trying to create a table that already exists but is empty, recreate the table rather than throwing a DatabaseSchemaObjectExistsException and previously by others in earlier comments, the patch from #1551132-72: When trying to create a table that already exists but is empty, recreate the table rather than throwing a DatabaseSchemaObjectExistsException is not good enough to be committed. Ignoring errors is bad practice.
Instead I suggest a patch that adds a special case: if a table already exists and is empty then drop it before trying to create it. (This helped in most of our use cases.)
To me that's a step in the good direction. We're still missing test coverage. And ideally - as suggested by the issue creator - the core schema system would be smart enough to upgrade the table structure to the wanted structure, if needed, and even if it contains data. https://www.drupal.org/project/schema could help with
I changed the Drupal version of this issue from Drupal 8 to Drupal 7 so the patch can be tested by the test bots. Changed issue tag "Needs backport to D7" to "Needs forward port to D8" accordingly.
Comment #88
sobi3ch commented#32 didn't worked for me, but #87 works like a charm. @PieterDC great job! I agree with suggested special case:
Comment #89
yasir.arefin commented#87 worked for me. Thanks
Comment #90
phpepe commentedThis is a great discussion, and explains what is happening to me when trying to install some commerce submodules, on a dirty database that has modules not uninstalled correctly.
I want to bring up here another related issue, but the opposite: Uninstall
When trying to uninsnstall a module that drops table that not exists, it throws the PDO execptio, stops the uninstall process execution and consequently do not complete the 100% of the table removal, and related queries. Probably sometimes, this issue may be the cause of the main error of this discussion. (because is you try to re-install the module again, you will find the initial 'table already exists error'
This is an example of my usecase:
A workaround that worked for my was adding couple of checks on field_sql_storage.module:
And an add " if (db_table_exists($table_name)) " around the update queries.
Comment #91
Robert_W commented#87 works for me on Drupal 7.56! I like the solution that checks if the table is empty and drops it if it is. This also fixes the exceptions that sometimes occurs with reverting Features.
Guess we can mark this as tested and reviewed? Code looks clean to me.
Comment #92
David_Rothstein commentedThis new approach is interesting and seems worth considering. I think in most cases this behavior is what we want, although can also imagine some scenarios where it isn't (e.g. two different modules trying to define a table with the same name; in that case you're going to get errors either way at some point down the line, so it's better to get them up front).
However, it still needs to be considered for Drupal 8 first.
It also looks like the patch is using functions that shouldn't be called from here:
Comment #94
bellagio commented#87 works for me on Drupal 7.59. Thank you.
Comment #96
nancydruI had originally UNINSTALLed (since you have no choice in 8.x) the Shortcut module and then came back to install it and got this error message. It needs to be fixed.
This has resulted in a site down hard.
Comment #97
nancydruComment #99
ibustosAdjusting the patch as it is no longer applies due to changes introduced in #2848822: Replace all calls to db_create_table, which is deprecated, #2848817: Replace all calls to db_table_exists, which is deprecated. and #2935256: Remove all usages of drupal_get_message and drupal_set_message in modules.
I agree this needs to be fixed.
Comment #100
ibustosComment #101
mcdoolz commentedIs there a legal way to do this in an extraneous module?
etc
There doesn't seem to be but maybe I'm missing something?
If I want to change the install process so that the system drops the tables outright (data or not, be damned, just recreate the tables!) is there some way I can do this? What would I hook into? What would I replace?
Comment #102
cilefen commentedI discovered something in #3043907-3: DatabaseCacheBackend::ensureBinExists() does not properly handle exceptions. If I am correct about that it may interest some people following this issue.
Comment #103
travisc commentedThe thing I love about Drupal is I'm still coming back to this thread 7 years later, and it's still going strong...
Comment #104
polAs long as it's not committed to D8, I can't push it forward in D7, sorry :(
Comment #105
cilefen commentedI think this is more fixable now that #3043907: DatabaseCacheBackend::ensureBinExists() does not properly handle exceptions is in.
Comment #107
summit commentedHi, thanks for patch #99! It is working great!
Greetings, Martijn
Comment #108
vladimirausPatch #87 tested successfully for Drupal 7.
Comment #109
daffie commented-1 The current way that the createTable() method works is that an exception is thrown when there is already a table with the new table name. Changing that would result is a BC break. And that is something we cannot do. Also deleting the existing table could result in a loss of data.
The current suggested patch does not do what the IS says.
Comment #110
daffie commentedAs a result of the previous comment, back to needs work.
Comment #112
pelicani commented@daffie
"Changing that would result is a BC break. And that is something we cannot do. Also deleting the existing table could result in a loss of data."
What is BC?
Also, the patch checks to see if the table is empty before removing it.
"The current suggested patch does not do what the IS says."
What is IS?
The initial submission asks a bunch of questions and is frustrated.
How can we move this forward to get the change committed in code?
Comment #113
vuilI rerolled the patch of #87 for Drupal 7.x-1.x and the latest stable Drupal core 7.72 versions.
Comment #115
tomefa commentedI rerolled the patch #99 for Drupal core 8.8.10
Comment #116
paulocsAdded tests for 9.2.x branch.
Comment #118
tim-dielsI rerolled the patch of #113 for Drupal 7.x-1.x and the latest stable Drupal core 7.83 version.
Comment #120
weekbeforenextI created a patch for 9.3.x, applying the strategy from comment #118 directly to the createTable() method in Schema.php. This move is based on drupal_install_schema() being deprecated in 9.2.0: https://www.drupal.org/node/2970993
Comment #122
bbombachiniTested patch from #115 on 9.2 and it works well.
Comment #123
catchThis shouldn't use messenger. I'm not sure if it's a good idea to do it at all, but if so and we want to have a message, it should use trigger_error(). Also needs test coverage.
Comment #124
ravi.shankar commentedMade changes as per comment #123, but still, need work for the test.
Comment #126
stmh commentedHi, we are using the patch from #120 and it introduces a lot of problems when you have more than one PHP workers, as the function is not atomic anymore. This might work in a single-threaded install but will fail with hard to debug concurrency issues when called by code on every request. The purge module for example tries to create a table if it does not exist prior which leads to a never ending series of table creation and -dropping as one function call form Worker A is intertwined with a function call from Worker B.
This happens under heavy load only, but still the offending code should be guarded by a lock.
Comment #128
chandeepkhosa commentedI can confirm that #115 solved the problem on Drupal core 8.9.20 (silver lining while upgrading a very out of date site).