Answers.Body: <p>Yep, that's it, check out the <a href="http://buildwithcraft.com/docs/plugins/records" rel="nofollow">Records documentation</a> to learn more:</p>
  
  <blockquote>
    <p>Active record models (or “records”) are like models, except with a
    database-facing layer built on top. On top of all the things that
    models can do, records can:</p>
    
    <ul>
    <li><strong>Define database table schemas</strong></li>
    <li>Represent rows in the database</li>
    <li>Find, alter, and delete rows</li>
    </ul>
  </blockquote>
  
  <p>Also, you might find <a href="http://buildwithcraft.com/docs/plugins/migrations" rel="nofollow">"Creating Database Migrations"</a> interesting.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-26T18:07:37.663Z
Answers.LastActivityDate: 2014-07-26T18:07:37.663Z
Answers.UserDisplayName: Victor
Answers.Body: <p><code>PluginNameRecord.php</code> is how Craft installs database tables. You can also have multiple tables by using <code>PluginName_TableRecord.php</code> where 'Table' will be the name of the new table in the database.</p>
  
  <p>Might also be worthwhile to mention that the cocktails recipe you linked to has a lot of issues as it has not been updated for the latest versions of Craft. </p>
  
  <p>Sean Delaney updated that plugin and the new repository is here: </p>
  
  <p><a href="https://github.com/seandelaney/cocktailrecipes" rel="nofollow">https://github.com/seandelaney/cocktailrecipes</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-21T03:55:43.013Z
Answers.Text: The delete option doesn't work for the updated version. Any ideas why??
Answers.UserDisplayName: Sandy D.
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-26T18:55:16.920Z
Answers.LastActivityDate: 2014-07-26T20:45:26.717Z
Answers.LastEditDate: 2014-07-26T20:45:26.717Z
Answers.UserDisplayName: Jason McCallister
Body: <p>I am absolutely new to craft plugin development and could not find any documentation on creating database tables specific to a new plugin. How are new tables created when a plugin is installed?</p>
  
  <p>I am browsing through the source code for the <code>CocktailRecipes</code> plugin: <a href="https://github.com/adrianmacneil/cocktailrecipes/" rel="nofollow">https://github.com/adrianmacneil/cocktailrecipes/</a> and I cannot find how the <code>craft_cocktailrecipes_ingredients</code> table gets created when I install it.</p>
  
  <p>Is it merely a matter of defining a record class like <code>CocktailRecipes_IngredientRecord</code> and then overriding the <code>getTableName</code> and <code>defineAttributes</code> methods?</p>
  
  <p>Is that how craft cms builds the tables?</p>
  
Tags: <plugin-development><database><migration>
Title: How do I create database tables for a craft cms plugin on install?
ThreadText: # How do I create database tables for a craft cms plugin on install?
  
  (Asked by: username_0 on 2014-07-26)
  
  I am absolutely new to craft plugin development and could not find any documentation on creating database tables specific to a new plugin. How are new tables created when a plugin is installed?
  
  I am browsing through the source code for the `CocktailRecipes` plugin: <https://github.com/adrianmacneil/cocktailrecipes/> and I cannot find how the `craft_cocktailrecipes_ingredients` table gets created when I install it.
  
  Is it merely a matter of defining a record class like `CocktailRecipes_IngredientRecord` and then overriding the `getTableName` and `defineAttributes` methods?
  
  Is that how craft cms builds the tables?
  
  **Tags:** plugin-development, database, migration
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2014-07-26. Score: 2 | Accepted answer
  
  Yep, that's it, check out the [Records documentation](http://buildwithcraft.com/docs/plugins/records) to learn more:
  
  > Active record models (or “records”) are like models, except with a
  > database-facing layer built on top. On top of all the things that
  > models can do, records can:
  >
  > * **Define database table schemas**
  > * Represent rows in the database
  > * Find, alter, and delete rows
  
  Also, you might find ["Creating Database Migrations"](http://buildwithcraft.com/docs/plugins/migrations) interesting.
  
  
  ---
  
  ### Answer by username_2 on 2014-07-26. Score: 4
  
  `PluginNameRecord.php` is how Craft installs database tables. You can also have multiple tables by using `PluginName_TableRecord.php` where 'Table' will be the name of the new table in the database.
  
  Might also be worthwhile to mention that the cocktails recipe you linked to has a lot of issues as it has not been updated for the latest versions of Craft.
  
  Sean Delaney updated that plugin and the new repository is here:
  
  <https://github.com/seandelaney/cocktailrecipes>
  
  > **Comments:**
  > **username_3**: The delete option doesn't work for the updated version. Any ideas why??  
  
  ---
  
  