2015-04-20 67 views
1

在MySQL中我添加了一個新列的表...NOT NULL默認1插入0和1

ALTER TABLE `articles` ADD `visible` NOT NULL DEFAULT (1) 

我使用了默認爲1有新的報道可見,如果一篇文章讓殘疾人,它將被更新爲0,這意味着它不能被查看。

現在,在新文章中插入代替插入默認1的MySQL,而是在某些行和其他一行上插入0。

我想知道是什麼導致這個問題和可能的解決方案,而不是必須手動更新這些行爲1。

的EG的刀片是...

INSERT INTO articles (filename, owner, name, descr, image1, image2, category, added, info_hash, size, numfiles, save_as, news, external, nfo, lang, anon,tube, last_action) VALUES (".sqlesc($fname).", '".$CURUSER['id']."', ".sqlesc($name).", ".sqlesc($descr).", '".$inames[0]."', '".$inames[1]."', '".$catid."', '" . get_date_time() . "', '".$infohash."', '".$articlesize."', '".$filecount."', ".sqlesc($fname).", '".$news."', '".$external."', '".$nfo."', '".$langid."','$anon', ".sqlesc($tube).",'".get_date_time()."')"); 

然後我試圖將其升級到

INSERT INTO articles (filename, owner, name, descr, image1, image2, category, added, info_hash, size, numfiles, save_as, news, external, nfo, lang, visible, anon,tube, last_action) VALUES (".sqlesc($fname).", '".$CURUSER['id']."', ".sqlesc($name).", ".sqlesc($descr).", '".$inames[0]."', '".$inames[1]."', '".$catid."', '" . get_date_time() . "', '".$infohash."', '".$articlesize."', '".$filecount."', ".sqlesc($fname).", '".$news."', '".$external."', '".$nfo."', '".$langid."','$visible', '$anon', ".sqlesc($tube).",'".get_date_time()."')"); 

而且

$visible = 1; 
+0

顯示我們的插件。 –

+0

不能幫助您,除非您向我們顯示導致此問題的插入查詢。 –

+1

這些應該是真正準備好的陳述。我假設'$ visible = 1;'出現在sql語句之前... – jeroen

回答

1

您需要定義要插入特定類型的列。一般的ALTER聲明應該遵循這種格式。

ALTER TABLE table_name ADD column_name column-definition; 

我假設你只是想有一個1或0,這樣下面應該工作:

ALTER TABLE `articles` ADD `visible` TINYINT NOT NULL DEFAULT 1 
2

你忘了添加的數據類型。

你可能想是這樣的:

ALTER TABLE `articles` ADD `visible` TINYINT NOT NULL DEFAULT 1 

如果不解決這個問題,你在你的代碼的某個地方設置的默認值。