Altering the database

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:08
    In this chapter, we are going to add another field
  • 0:10
    to our already existing database table.
  • 0:13
    If we take a look at our code,
  • 0:15
    we previously defined our schema to have 3 fields,
  • 0:20
    the nid, the uid, and the view_count,
  • 0:23
    and we set our primary keys as the nid and the uid.
  • 0:28
    I mentioned that if you are enabling this module for the first time,
  • 0:32
    your schema will automatically be installed.
  • 0:35
    But since we already had our module enabled, we created a hook to update the database,
  • 0:42
    and we ran Drupal install schema, and that way, our tables got created.

Altering the Database

Loading...

In this chapter we learn about changing the definition of a database table after it has already been installed. This example expands on the previous chapters by adding a new field to the table to collect the date a user last visited a node. We learn more about hook_update_N() as well as db_add_field().

Downloads: 
Log in or sign up to download companion files.
Additional resources: