开发者

MySQL Query Works on My Laptop, but Not on Server

I worked on a site locally through my Laptop. I have a table named blog and it has the fields post_id, title, markdown, author, added, and modified.

The fields Added and Modified are both DATETIME's.

When a user makes a blog post, PHP runs this query successfully: INSERT INTO blog (title, author, markdown, added) VALUES ('BLA', 'BLA', 'BLA', NOW())

I've gone into phpMyAdmin and ran the exact same query with working results.

Now, I exported my exact database into the server today and I noticed that no posts were being stored in the DB, so I tried running it through phpMyAdmin's SQL and it gave me the error Field 'modified' doesn't have a default value.

Why would this be happe开发者_如何转开发ning? In my database, the default for both is None so I'm quite confused on what could be causing this.

My Laptop has PHP 5.3.1 and MySQL 5.1.41 (I installed XAMPP.) The Server has PHP 5.3.5 and MySQL 5.5.8 (Out of desperation I installed the newest versions. The server was originally running MySQL 5.1 and a lower version of PHP.)

This has been killing me, hopefully someone knows what's wrong with this or how to fix it.

Edit: Here are the SHOW CREATE TABLE blog results.

Laptop:

| blog  | CREATE TABLE `blog` (
  `post_id` mediumint(9) NOT NULL AUTO_INCREMENT,
  `title` varchar(160) NOT NULL,
  `author` varchar(100) NOT NULL,
  `markdown` longtext NOT NULL,
  `added` datetime NOT NULL,
  `modified` datetime NOT NULL,
  PRIMARY KEY (`post_id`)
) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=latin1 |

Server:

| blog  | CREATE TABLE `blog` (
  `post_id` mediumint(9) NOT NULL AUTO_INCREMENT,
  `title` varchar(160) NOT NULL,
  `author` varchar(100) NOT NULL,
  `markdown` longtext NOT NULL,
  `added` datetime NOT NULL,
  `modified` datetime NOT NULL,
  PRIMARY KEY (`post_id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 |

Auto Increments are different because of my tests.


ALTER TABLE blog CHANGE modified modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP; 

Or, more rarely, you might have a buggy version of MySQL on your server.

*I might have the syntax imperfect, I referred to the last comment on ALTER TABLE at the bottom of the manual page.


First: are you sure the data on your laptop exactly the same as the data on the server? Maybe you're not getting this error on your laptop because the default values are set on your laptop table somehow and not the server -- possibly an issue with how you exported the data.

When you say, the default is "None" do you mean NULL or do you mean literally the word "None"?

If both fields are datetime fields, then set the default to NOW() or, if you prefer to not have an actual date and time by default, use a string like "0000-00-00 00:00:00", or the JDBC friendly "0001-01-01 00:00:00".

Compare the structure of each table with the following command in a mysqlclient:

SHOW CREATE TABLE blog;


Dump the DDL from both versions using

$ mysqldump --no-data dabasename

and compare them (and check the man page for mysqldump(1) as I'm flying by memory here.)

Make sure you're using the same exact table description and that both versions are using the same engine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜