Questions tagged [drupal-schema]

The Schema API allows modules to declare their database tables in a structured array (similar to the Form API). If your question is about the database API, and not the schema API, don't use this tag.

Introduced in Drupal 6, the Schema API allows modules to declare their database tables in a structured array (similar to the Form API) and provides API functions for creating, dropping, and changing tables, columns, keys, and indexes.

Database schemas and their abstractions are a large topic in computer science and software development. Drupal's Schema API 1 is a fairly simple approach. Even so, it provides several benefits:

  • No more separate CREATE TABLE or ALTER TABLE statements for each database. Module developers only need to create a schema structure and/or use the Schema API functions, and Drupal takes care of the rest. This makes writing install and update functions much simpler. Use hook_schema_alter() to make changes to existing schema.
  • Since the API makes it equally easy for module developers to support all databases, Drupal's support for PostgreSQL will improve substantially. Also, as new database engines such as Oracle, SQLite, or Microsoft SQL Server are supported, modules using the Schema API will automatically work with them.
  • Several advanced capabilities, such as incremental database updates, a simple and consistent CRUD API, form scaffolding, simpler CCK and Views, schema and data validation, become much easier to implement in future enhancements.

Relevant links:

13 questions
4
votes
1 answer

drupal 7 custom schema error datetime

I have the following schema (generated from an existing table with the schema module (7.x-1.0-beta3) in a custom module. function myproject_entities_schema() { // --------------------------------------------------------------------------------- //…
dschenk
  • 315
  • 2
  • 13
4
votes
1 answer

Multiple primary keys in a schema

I have this schema which I need to define two primary keys; one is Drupal's 'vid' field and the other one is my site 'bid' field which is of auto increment type which in turn requires it to be a primary key: wtherwise I get MySQL error. I'm having…
Andrew
  • 1,035
  • 7
  • 22
  • 40
3
votes
3 answers

Foreign keys in Drupal 7 schema trouble

I have a trouble with Drupal 7 schema for module. There are 4 tables but for sample 2 will be enough: function mymodule_schema() { $schema['series'] = array( 'fields' => array( 'id' => array( 'type' => 'serial', …
2
votes
3 answers

Please Explain Drupal schema and drupal_write_record

1) Where is the best place to populate a new database table when a module is first installed, enabled? I need to go and get some data from an external source and want to do it transparently when the user installs/enables my custom module. I create…
Aaron
  • 3,249
  • 4
  • 35
  • 51
1
vote
2 answers

Add custom field to content type

I create content type tv-rate-plus-ethernet via admin panel, now I neeed add to this content type custom field channel_reference, where channel_reference field return checkboxes list with channel data from custom table ks_channel. Example we have…
1
vote
3 answers

"created" and "updated" columns in mysql table drupal

Mysql does not allow two auto-updating timestamps columns in the same database table. However, many people like to have "created" and "updated" columns for their tables because that sort of information is useful, so there must be some work around.…
anduril
  • 199
  • 2
  • 10
1
vote
2 answers

Drupal 7 hook_schema not installing database table

Any help would be brilliant. function request_gold_pack_schema() { $schema['request_gold_pack_customer_details'] = array( 'description' => 'Table to store all customer details.', 'fields' => array( 'rid' =>…
Richard Skinner
  • 738
  • 3
  • 10
  • 26
1
vote
1 answer

Using drupal_write_record to do insert_or_update

OK, so I read about drupal_write_record, which apparently serves as a function which does an insert_or_update. However from what I've read, it doesn't know by itself whether to do the insert or the update, but this is determined by the existence (or…
Eduard Luca
  • 6,514
  • 16
  • 85
  • 137
0
votes
1 answer

Drupal table creation error

I am trying to create a table in Drupal database using hook_schema function but I am getting the PDO exception error which I could not resolve. It would be great if you could provide me an solution to my issue PDOException: SQLSTATE[42000]: Syntax…
H4v0cCr8oR
  • 133
  • 11
0
votes
1 answer

drupal 6: schema api to specify exact size of int data type

Using the Drupal 6 schema API, how do you specify the EXACT size of an int data type? For example, I can do the below query in MySQL: create table test (foo int(11) unsigned not null); The drupal 6 schema API only gives me these fixed sizes options…
user785179
  • 919
  • 5
  • 14
  • 24
0
votes
1 answer

Drupal schema for text_with_summary in install file

I'm a drupal newbie. In Drupal 7, I have an install file and I'm trying to get the schema to work for a text_with_summary. Maybe I'm going about this the wrong way but I am using a form's install file to create the databases I will need. I just…
purplerice
  • 473
  • 1
  • 6
  • 22
0
votes
1 answer

Drupal field values and longtext

Long time mysql/php user, first time Drupal user. Actually, I'm not doing the Drupal development (I'm just using the database to pull in some data to a separate application), and I'm just trying to figure out if this is how it's supposed to…
typeoneerror
  • 55,990
  • 32
  • 132
  • 223
0
votes
1 answer

Bulk update text format for imported drupal nodes

I've been migrating a sites content without much luck: The content was being imported, but the body text not displayed. I just tried to change the input text format, and the content is now displayed. (I guess those are the original values.) I tried…
James Kirkby
  • 1,716
  • 5
  • 24
  • 46