Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I am trying to display an already existing table to Drupal Views. This table exists within my current Drupal Database, along with my Drupal tables.

The table's name is ACCOUNT_PNL and I would like to expose the fields in this table to Drupal Views.

I've followed the instructions here, but when I go and enable this module, I get the following error from my site:

DatabaseSchemaObjectExistsException: Table <em class="placeholder">ACCOUNT_PNL</em> already exists. in DatabaseSchema->createTable() (line 657 of /var/www/drupal7/includes/database/schema.inc).

I understand that the table already exists, but isn't the tutorial code supposed to only "expose" it to Views so I can then use Views to display it?

Perhaps there is an error in my understanding, any help would be appreciated.

share|improve this question

1 Answer

The tutorial you linked to implements hook_schema() which means Drupal will want to take care of the table implementation for you.

I don't know this for definite but I think Views requires that the table be under Drupal's control when you're exposing custom data.

I don't know of a way to tell the installer to ignore the schema installation, so the simplest thing to do would probably be to rename the custom table temporarily, install the module (allowing Drupal to create the table), then import the data from the temp table into the newly created one.

If you then uninstall the module (not just disable), your custom table and the data will be lost so it's worth keeping a backup if you think that's likely to happen.

share|improve this answer
That all seems very complicated. Would you know how I can give my tables(s) to be under the control of Drupal? Or to simply just let Views display the rows in my table? – chlong Jun 12 '12 at 17:30
I guess you could go into the system table and manually set the status of your module to 1...that would make Drupal think the module's already been installed. You'd need to clear the caches after doing that – Clive Jun 12 '12 at 18:06
1  
If the table already exists in Drupal wouldn't you use hook_schema_alter rather than hook_schema to modify the DB? – Citricguy Aug 13 '12 at 5:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.