我正在尝试使用MySQL Workbench中的以下语法创建一个SQL表(在Mac OS中),
CREATE TABLE orders (
order_id INT NOT NULL PRIMARY KEY,
company_id INT NOT NULL,
customer_id INT NOT NULL,
order_number VARCHAR(200),
order_date TIMESTAMP NOT NULL,
created TIMESTAMP NOT NULL,
order_status INT NOT NULL,
CONSTRAINT orders_fk_company
FOREIGN KEY (company_id) REFERENCES companies (company_id),
CONSTRAINT orders_fk_customer
FOREIGN KEY (customer_id) REFERENCES customers (customer_id)
);
当我尝试执行此脚本时,我收到以下消息,
Error code: 1067. Invalid default value for 'created'
这里有什么问题以及如何正确创建表格?我有其他2个表,即下面提供的公司和客户。有正确的执行,没有问题。
CREATE TABLE companies (
company_id INT NOT NULL PRIMARY KEY,
company_name VARCHAR(50) NOT NULL,
contact_name VARCHAR(50) NOT NULL,
contact_phone VARCHAR(30) NOT NULL,
contact_email VARCHAR(50) NOT NULL,
created DATETIME NOT NULL
);
CREATE TABLE customers (
customer_id INT NOT NULL PRIMARY KEY,
company_id INT NOT NULL,
customer_name VARCHAR(100) NOT NULL,
customer_company VARCHAR(100),
CONSTRAINT customers_fk_company
FOREIGN KEY (company_id) REFERENCES companies (company_id)
);