Autogenerating database schema

ColdFusion automatically creates tables when ORM is initialized for the application. For auto-generating tables, do the following:

In the THIS scope of Application.cfc, in ormsettings struct, set the dbCreate property to one of the following values:
  • update: Creates the table (if it does not exist) or updates the table (if it exists).

  • dropcreate: Drops the table if it exists and then creates it.

For example,
<cfset this.ormsettings.dbCreate="update">

Certain specific attributes (DDL-only attributes) defined for the tags cfcomponent and cfproperty can be use to define various attributes for the auto-generated tables and columns. DDL-only attributes are used only for DDL generation. For details of these attributes, see the table in the section DDL-only attributes in Column.

Examples

Application.cfc
<cfset this.name = "AG"/>
<cfset this.ormenabled=true/>
<cfset this.datasource = "ORM_DDL">
<cfset this.ormsettings.dbCreate="dropcreate">
<cfset this.ormsettings.sqlscript="mysqlscript.sql">

Artists.cfc

<cfcomponent persistent="true" table="Artists">
      <cfproperty name="artistid" fieldtype="id" ormtype="integer" length=10>
      <cfproperty name="firstname" ormtype="string" length="20" notnull="true">
      <cfproperty name="lastname" ormtype="string" length="20" notnull="true">
      <cfproperty name="address"  ormtype="string" length="50">
      <cfproperty name="city" ormtype="string" length="20">
      <cfproperty name="state" ormtype="string" length="2">
      <cfproperty name="postalcode" ormtype="string" length="10">
      <cfproperty name="email" ormtype="string" length="50" unique="true">
      <cfproperty name="phone" ormtype="string" length="20">
      <cfproperty name="fax" ormtype="string" length="12">
      <cfproperty name="thepassword" ormtype="string" length="20">
</cfcomponent>
art.cfc
<cfcomponent persistent="true" table="Art">
      <cfproperty name="artid" generator="identity" fieldtype="id">
      <cfproperty name="artname" ormtype="string" length="50">
      <cfproperty name="price" ormtype="double">
      <cfproperty name="largeimage" ormtype="string" length="30">
      <cfproperty name="mediaid" ormtype="integer" length="10">
      <cfproperty name="issold" ormtype="boolean" dbdefault=1>
      <cfproperty name="artist" fkcolumn="artistid" fieldtype="many-to-one" cfc="CArtists">
</cfcomponent>