I want create table with string primary key.
Product_Category model:
class Product_Category < ActiveRecord::Base
self.primary_key = "product_category_name"
self.table_name = "product_category"
belongs_to :shop_category
validates :product_category_name, uniqueness: true
end
Migration:
class CreateProductCategory < ActiveRecord::Migration
def change
create_table :product_category, id: false do |t|
t.string :product_category_name, null: false
t.string :shop_category_id
t.boolean :disable_product_category
end
execute "ALTER TABLE 'product_category' ADD PRIMARY KEY ('product_category_name')"
end
end
But after rake db:migrate I receive:
rake db:migrate
?== CreateProductCategory: migrating ==========================================
-- create_table(:product_category, {:id=>false})
-> 0.0381s
-- execute("ALTER TABLE 'product_category' ADD PRIMARY KEY ('product_category_name')")
rake aborted!
An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: near "PRIMARY": syntax error: ALTER TABLE 'product_category' ADD PRIMARY KEY ('product_category_name')E:/androcommerce/admin_backend/db/migrate/20140414145913_create_product_category.rb:8:in `change'
C:in `migrate'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I don't understand why. Syntax is true.