change_column_default(table_name, column_name, default)
You can use this method to change the default value for the specified column. Unfortunately,
you cannot use it to set the default value of a column to NULL. To do that, you must use
DatabaseStatements#execute to run the appropriate SQL statement manually.
This method raises a NotEmplementedError by default and must be implemented by the
specific database connection adapters.
columns(table_name, name = nil)
columns returns an Array of Column objects for the given table.
create_table(name, options = {}) { || . . . }a
This method creates a new table with the given name, and by default, automatically adds
a column for the primary key to the table.
You can use the method either in regular or block form. The regular form does not add
any columns besides the one for the primary key to the table, and you would then use
add_column to add additional columns to the table.
For example, we could use the regular form of this method to create our accounts table:
create_table(:accounts)
add_column(:accounts, :first_name, :string)
add_column(:accounts, :last_name, :string)
add_column(:accounts, email, :string)
APPENDIX ?– ACTIVE RECORD METHODS IN DETAIL 242
However, if, instead, you wish to use the block form of this method to create the same
table, the code would be
create_table(:accounts) do |t|
t.
Pages:
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534