How can I move one schema into another with different fields? - mysql

I created an application to replace a legacy one that we had for a while, and I need to move the old database records into the new system, but the schemas are not the same. I'm wondering if there is any way to move the old schema into the new, ignoring the fields that don't exist in the new table, and moving fields that have changed to their updated version.
My old schema is Microsoft SQL Server and has the following fields:
[req_id] [int] IDENTITY(1,1) NOT NULL,
[req_user_id] [nvarchar](50) NOT NULL,
[req_subject] [nvarchar](200) NOT NULL,
[req_details] [nvarchar](4000) NOT NULL,
[req_request_date] [date] NOT NULL,
[req_year] [smallint] NOT NULL,
[req_expect_date] [date] NOT NULL,
[leader] [nvarchar](10) NULL,
[member1] [nvarchar](10) NULL,
[member2] [nvarchar](10) NULL,
[member3] [nvarchar](10) NULL,
[member4] [nvarchar](10) NULL,
[member5] [nvarchar](10) NULL,
[member6] [nvarchar](10) NULL,
[status_code] [nvarchar](10) NULL,
[hours_used] [int] NULL,
[completed_date] [date] NULL,
[category_code] [nvarchar](10) NULL,
[staff_comments] [nvarchar](2000) NULL,
[response_Email] [bit] NOT NULL,
[response_Phone] [bit] NOT NULL,
[response_Fax] [bit] NOT NULL,
[response_online_upload] [bit] NOT NULL,
[response_post_mail] [bit] NOT NULL,
[response_file] [bit] NOT NULL,
[response_pickup] [bit] NOT NULL,
My new schema is MySQL and looks like this:
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`userid` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`subject` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`details` text COLLATE utf8_unicode_ci NOT NULL,
`eta` date NOT NULL,
`leader` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`member1` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`member2` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`member3` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`member4` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`member5` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`member6` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`status` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`time_spent` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`date_completed` date DEFAULT NULL,
`category` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`comments` text COLLATE utf8_unicode_ci,
`response_method` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
Is there any way to do this and salvage our old records in the new system?

I used the Data Export tool to generate an xlsx file, then used Navicat to import it as a new table to the database, and then used simple inserts statements to move the data to the other table. I was appalled by the response this question got on SO, but I'm glad I found a solution on my own.

Related

Improving MySQL Update Performance

I've got a process to import/update data from a CSV file. The process of saving that data from the csv to a "temp" table works fine. (temp_mls_transactions)
The next step is to update the existing records in the production table (tbl_mlsTransactions) with the data from the "temp" table. This step is causing the issue. IF it completes, its about 17 minutes for 7k records.
After the update is complete, we delete the common records from the "temp" table. Then insert the remaining records.
Here is the update query:
UPDATE tbl_MLSTransactions mt USE INDEX(idx_mlsNumber_association) INNER JOIN temp_mls_import temp USE INDEX (idx_mlsAssociationID_mlsID) ON mt.mlsNumber=temp.mlsNumber AND mt.mlsAssociationID=temp.mlsAssociationID
SET mt.activeStatusDate=temp.activeStatusDate,
mt.closeDate=temp.closeDate,
mt.closePrice=temp.closePrice,
mt.coListAgentMLSID=temp.coListAgentMLSID,
mt.coSellingAgentMLSID=temp.coSellingAgentMLSID,
mt.currentPrice=temp.currentPrice,
mt.dateAvailable=temp.dateAvailable,
mt.daysToClose=temp.daysToClose,
mt.daysToContract=temp.daysToContract,
mt.DOM=temp.DOM,
mt.expectedClosingDate=temp.expectedClosingDate,
mt.expirationDate=temp.expirationDate,
mt.address=temp.address,
mt.address2=temp.address2,
mt.city=temp.city,
mt.state=temp.state,
mt.zip=temp.zip,
mt.lastChangeType=temp.lastChangeType,
mt.lastDateAvailable=temp.lastDateAvailable,
mt.lastListPrice=temp.lastListPrice,
mt.lastStatus=temp.lastStatus,
mt.latitude=temp.latitude,
mt.listAgentMLSID=temp.listAgentMLSID,
mt.listPrice=temp.listPrice,
mt.listingContractDate=temp.listingContractDate,
mt.longitude=temp.longitude,
mt.originalListPrice=temp.originalListPrice,
mt.pendingDate=temp.pendingDate,
mt.propertyStatus=temp.propertyStatus,
mt.sellingAgentMLSID=temp.sellingAgentMLSID,
mt.status=temp.status,
mt.statusContractualSearchDate=temp.statusContractualSearchDate,
mt.withdrawnDate=temp.withdrawnDate,
mt.withdrawnStatus=temp.withdrawnStatus,
mt.listOfficeMLSID=temp.listOfficeMLSID,
mt.coListOfficeMLSID=temp.coListOfficeMLSID,
mt.sellingOfficeMLSID=temp.sellingOfficeMLSID,
mt.coSellingOfficeMLSID=temp.coSellingOfficeMLSID;
Here is the create statement for the "temp" table
CREATE TABLE `temp_mls_import` (
`tempID` int(11) NOT NULL AUTO_INCREMENT,
`activeStatusDate` date DEFAULT NULL,
`address` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`address2` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`city` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`state` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`zip` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`availability` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`bathsFull` int(11) DEFAULT NULL,
`bathsHalf` int(11) DEFAULT NULL,
`bathsTotal` decimal(10,2) DEFAULT NULL,
`bedsTotal` decimal(10,2) DEFAULT NULL,
`CDOM` int(11) DEFAULT NULL,
`closeDate` date DEFAULT NULL,
`closePrice` decimal(15,2) DEFAULT NULL,
`coListAgentMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`coListOfficeMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`coSellingAgentMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`coSellingOfficeMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`contractStatus` varchar(25) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`county` varchar(25) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`currentPrice` decimal(15,2) DEFAULT NULL,
`dateAvailable` date DEFAULT NULL,
`daysToClose` int(11) DEFAULT NULL,
`daysToContract` int(11) DEFAULT NULL,
`DOM` int(11) DEFAULT NULL,
`expectedClosingDate` date DEFAULT NULL,
`expectedLeaseDate` date DEFAULT NULL,
`expirationDate` date DEFAULT NULL,
`expirationRenewalDate` date DEFAULT NULL,
`lastChangeType` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`lastDateAvailable` date DEFAULT NULL,
`lastListPrice` decimal(15,2) DEFAULT NULL,
`lastStatus` varchar(25) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`latitude` float DEFAULT NULL,
`listAgentMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`listOfficeMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`listPrice` decimal(15,2) DEFAULT NULL,
`listingContractDate` date DEFAULT NULL,
`longitude` float DEFAULT NULL,
`mlsNumber` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`offMarketDate` date DEFAULT NULL,
`officePrimaryBoardID` varchar(25) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`originalEntryTimestamp` timestamp NULL DEFAULT NULL,
`originalListPrice` decimal(15,2) DEFAULT NULL,
`PDOM` int(11) DEFAULT NULL,
`pendingDate` date DEFAULT NULL,
`photoCount` int(11) DEFAULT NULL,
`postalCodePlus4` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`priceChangeTimestamp` timestamp NULL DEFAULT NULL,
`propertyStatus` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`propertyType` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`providerModificationTimestamp` timestamp NULL DEFAULT NULL,
`realtorComYN` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`sellingAgentMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`sellingOfficeMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`SPLPRatio` decimal(10,2) DEFAULT NULL,
`sqftHeated` decimal(10,2) DEFAULT NULL,
`sqftTotal` decimal(10,2) DEFAULT NULL,
`status` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`statusChangeTimestamp` timestamp NULL DEFAULT NULL,
`statusContractualSearchDate` date DEFAULT NULL,
`teamName` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`tempOffMarketDate` date DEFAULT NULL,
`unitNumber` int(11) DEFAULT NULL,
`withdrawnDate` date DEFAULT NULL,
`withdrawnStatus` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`yearBuilt` int(11) DEFAULT NULL,
`mlsAssociationID` int(11) DEFAULT NULL,
PRIMARY KEY (`tempID`),
KEY `idx_mlsAssociationID_mlsID` (`mlsNumber`,`mlsAssociationID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
And here is the create statement for the production table
CREATE TABLE `tbl_mlstransactions` (
`transactionID` int(11) NOT NULL AUTO_INCREMENT,
`activeStatusDate` date DEFAULT NULL,
`address` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`address2` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`city` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`state` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`zip` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`availability` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`bathsFull` int(11) DEFAULT NULL,
`bathsHalf` int(11) DEFAULT NULL,
`bathsTotal` decimal(10,2) DEFAULT NULL,
`bedsTotal` decimal(10,2) DEFAULT NULL,
`CDOM` int(11) DEFAULT NULL,
`closeDate` date DEFAULT NULL,
`closePrice` decimal(15,2) DEFAULT NULL,
`coListAgentMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`coListOfficeMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`coSellingAgentMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`coSellingOfficeMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`contractStatus` varchar(25) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`county` varchar(25) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`currentPrice` decimal(15,2) DEFAULT NULL,
`dateAvailable` date DEFAULT NULL,
`daysToClose` int(11) DEFAULT NULL,
`daysToContract` int(11) DEFAULT NULL,
`DOM` int(11) DEFAULT NULL,
`expectedClosingDate` date DEFAULT NULL,
`expectedLeaseDate` date DEFAULT NULL,
`expirationDate` date DEFAULT NULL,
`expirationRenewalDate` date DEFAULT NULL,
`lastChangeType` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`lastDateAvailable` date DEFAULT NULL,
`lastListPrice` decimal(15,2) DEFAULT NULL,
`lastStatus` varchar(25) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`latitude` float DEFAULT NULL,
`listAgentMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`listOfficeMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`listPrice` decimal(15,2) DEFAULT NULL,
`listingContractDate` date DEFAULT NULL,
`longitude` float DEFAULT NULL,
`mlsNumber` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`offMarketDate` date DEFAULT NULL,
`officePrimaryBoardID` varchar(25) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`originalEntryTimestamp` timestamp NULL DEFAULT NULL,
`originalListPrice` decimal(15,2) DEFAULT NULL,
`PDOM` int(11) DEFAULT NULL,
`pendingDate` date DEFAULT NULL,
`photoCount` int(11) DEFAULT NULL,
`postalCodePlus4` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`priceChangeTimestamp` timestamp NULL DEFAULT NULL,
`propertyStatus` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`propertyType` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`providerModificationTimestamp` timestamp NULL DEFAULT NULL,
`realtorComYN` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`sellingAgentMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`sellingOfficeMLSID` varchar(250) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`SPLPRatio` decimal(10,2) DEFAULT NULL,
`sqftHeated` decimal(10,2) DEFAULT NULL,
`sqftTotal` decimal(10,2) DEFAULT NULL,
`status` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`statusChangeTimestamp` timestamp NULL DEFAULT NULL,
`statusContractualSearchDate` date DEFAULT NULL,
`teamName` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`tempOffMarketDate` date DEFAULT NULL,
`unitNumber` int(11) DEFAULT NULL,
`withdrawnDate` date DEFAULT NULL,
`withdrawnStatus` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`yearBuilt` int(11) DEFAULT NULL,
`mlsAssociationID` int(11) DEFAULT NULL,
PRIMARY KEY (`transactionID`),
KEY `idx_agentListInfo` (`listAgentMLSID`(191),`coListAgentMLSID`(191),`closeDate`,`status`),
KEY `idx_agentSellInfo` (`sellingAgentMLSID`(191),`coSellingAgentMLSID`(191),`closeDate`,`status`),
KEY `IDX_listAgentMLSID` (`listAgentMLSID`(191)) USING BTREE,
KEY `idx_coListAgentMLSID` (`coListAgentMLSID`(191)),
KEY `IDX_sellingAgentMLSID` (`sellingAgentMLSID`(191)) USING BTREE,
KEY `idx_coSellingAgentMLSID` (`coSellingAgentMLSID`(191)),
KEY `idx_productionSearch` (`mlsAssociationID`,`status`,`closeDate`),
KEY `idx_agentIDs` (`listAgentMLSID`(191),`coListAgentMLSID`(191),`sellingAgentMLSID`(191),`coSellingAgentMLSID`(191)),
KEY `idx_closeDate` (`closeDate`),
KEY `idx_mlsNumber_association` (`mlsNumber`,`mlsAssociationID`)
) ENGINE=InnoDB AUTO_INCREMENT=4543783 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
The import is not currently running, but here is the output from the explain statement on the update query
id,select_type,table,partitions,type,possible_keys,key,key_len,ref,rows,filtered,Extra
1,SIMPLE,temp,NULL,ALL,idx_mlsAssociationID_mlsID,NULL,NULL,NULL,1,100.00,"Using where"
1,UPDATE,mt,NULL,ref,idx_mlsNumber_association,idx_mlsNumber_association,128,"agenttracker.temp.mlsNumber,agenttracker.temp.mlsAssociationID",1,100.00,NULL
Any suggestions on how to make this quicker?
UPDATE:
I ran a few different files and when the ID's (MlsNumber, AgentID's, etc) are shorter (i.e. 5-10 characters) the update completes in 0.25 seconds. When they are longer (i.e. 25-27 characters) is when there is a problem.
Here are a couple examples of the long and short MLS Numbers:
20191104230040909159000000
20191104230040909159000000
20191104230040909159000000
Short:
4PRW01
20593419
20698727

MySQL 1366 incorrect integer value

I am trying to import a csv file into a MySQL DB.
Said csv file is from a select * from the same table
LOAD DATA INFILE 'C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/import.csv'
INTO TABLE fisc_hist_header
character set utf8
FIELDS TERMINATED BY ';'
LINES TERMINATED BY '\n'
(-- a whole lot of fields ...)
SET `CREATED_DATE`=STR_TO_DATE( #yourdatecolumn, '%d/%m/%Y %H:%i:%s' )
The file starts with
545752715002093599;3;1;503955117000124560;28/11/2019 14:38:51;0 -- all the other fields
What I get is
After searching here, all results are for
Incorrect integer value: ''
What is different and strange to me is that for me, it gets the value but does not inputs it as an integer ?
EDIT : As asked here is the create table statement:
CREATE TABLE `fisc_hist_header` (
`fiscal_idx` bigint(20) NOT NULL AUTO_INCREMENT,
`invc_sid` bigint(20) NOT NULL,
`sbs_no` int(11) NOT NULL,
`store_no` int(5) NOT NULL,
`workstation_id` bigint(20) NOT NULL,
`created_date` datetime NOT NULL,
`invc_type` int(11) NOT NULL,
`cashier_name` varchar(8) COLLATE utf8_bin DEFAULT NULL,
`associate_name` varchar(8) COLLATE utf8_bin DEFAULT NULL,
`store_code` varchar(5) COLLATE utf8_bin DEFAULT NULL,
`store_name` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`store_address1` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`store_address2` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`store_address3` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`store_address4` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`store_address5` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`store_address6` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`store_zip` varchar(10) COLLATE utf8_bin DEFAULT NULL,
`customer_sid` bigint(20) DEFAULT NULL,
`customer_title` varchar(15) COLLATE utf8_bin DEFAULT NULL,
`customer_last_name` varchar(30) COLLATE utf8_bin DEFAULT NULL,
`customer_first_name` varchar(30) COLLATE utf8_bin DEFAULT NULL,
`customer_address1` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`customer_address2` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`customer_address3` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`customer_address4` varchar(40) COLLATE utf8_bin DEFAULT NULL,
`customer_zip_code` varchar(10) COLLATE utf8_bin DEFAULT NULL,
`customer_country` varchar(35) COLLATE utf8_bin DEFAULT NULL,
`customer_phone` varchar(30) COLLATE utf8_bin DEFAULT NULL,
`customer_email` varchar(60) COLLATE utf8_bin DEFAULT NULL,
`item_count` int(5) NOT NULL,
`grand_total_receipt` decimal(10,0) NOT NULL,
`prism_version` varchar(19) COLLATE utf8_bin DEFAULT NULL,
`plugin_version` varchar(19) COLLATE utf8_bin DEFAULT NULL,
`flag_first_record` char(1) COLLATE utf8_bin DEFAULT NULL,
`signature_key` varchar(500) COLLATE utf8_bin DEFAULT NULL,
`signature` varchar(500) COLLATE utf8_bin DEFAULT NULL,
`signature_previous` varchar(500) COLLATE utf8_bin DEFAULT NULL,
`signature_short` varchar(10) COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (`fiscal_idx`),
UNIQUE KEY `un_fhh` (`invc_sid`)
) ENGINE=InnoDB AUTO_INCREMENT=364 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
As per the documentation for integer values, the maximum value for an unsigned integer which can be held in an INT column is 4294967295. For a standard signed integer it's 2147483647.
Your number 545752715002093599 is larger than both of these. You'll need to declare the target column as BIGINT in your fisc_hist_header table - the max value for a signed integer in this column type is 9223372036854775807.
These restrictions exist because of the number of bytes used by MySQL to store each value in the database. If you know you won't need to store values above a certain limit, you can use a smaller integer type in order to save disk space and memory.

Unrecognized data type - MYSQL

I created a database table in MySQL, but it would show up errors. Please help to solving this issue and constructive feedback is appreciated.
CREATE TABLE `bldsvs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`monday` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`tuesday` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`wednesday` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`thursday` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`friday` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`saturday` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`sunday` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
'positionID` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
`status` enum('1','0') COLLATE utf8_unicode_ci NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Laravel where method won't works correctly on my server but work right on my Mac

I have a weird problem, this line wont fetch any record on my server but works all right on my computer, mysql and php version are same, and when i cast id field to string it's work on server (Debian), but it is risky because i use where statement with id very much. this is the code:
$myAnswers=Questioner::where('id',$questioner_id)->first()->getLinkedAnsweres()->where("subject_id",Auth::user()->id);
and when i change it to this, it's work right (cast id to string):
$myAnswers=Questioner::where('id',$questioner_id)->first()->getLinkedAnsweres()->where("subject_id",(string)Auth::user()->id);
subject_id and user id are both unsigned_integer with same size.
How can i fix this problem? Should i overwrite where method? or is there any config which cast unsigned int to string in query?
thanks
PS: Tables structure:
users | CREATE TABLE `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`family` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`username` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`gender` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`age` int(11) DEFAULT NULL,
`password` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`default_password` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`access_level` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'subject',
`phone` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`comments` longtext COLLATE utf8_unicode_ci,
`project_limit` int(10) unsigned NOT NULL,
`questioner_limit` int(10) unsigned NOT NULL,
`created_by` int(10) unsigned DEFAULT NULL,
`remember_token` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `users_username_unique` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci |
answers | CREATE TABLE `answers` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`question_id` int(10) unsigned NOT NULL,
`selected_option` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`subject_id` int(10) unsigned NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci |

MySQL Update Issue - NULL fields get updated, but not fields already containing data

I am struggling with a MySQL query. Here's the problem:
SELECT * from sf_forecasts WHERE contentid='1234' AND fulldate='2012-12-13'
There is one record in my table that matches this criteria, and this query finds it with no difficulty. However, when I move to update it using this query...
UPDATE sf_forecasts
SET listingTitle ='Some Snow Resort', location ='49.23, -115.22'
WHERE contentid='1234' AND fulldate='2012-12-13'
...I always get a notice of "0 rows affected." Strangely, the query is actually updating the record, but it's only touching fields that are NULL. If my example record has a 'location' value of NULL, the query will update the data, but if it already contains a non-NULL value, the query will not change it, even though the query clearly contains new information.
What gives?
P.S. I am using a PRIMARY key of contentid+fulldate (b-tree, unique) if this matters.
P.S.S. Here is the 'SHOW CREATE TABLE sf_forecasts' results as requested below:
sf_forecasts CREATE TABLE `sf_forecasts` (
`contentid` int(11) NOT NULL,
`fulldate` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`listingTitle` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`location` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`dayofmonth` smallint(2) NOT NULL,
`dayofweek` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`minTempF` smallint(4) NOT NULL,
`maxTempF` smallint(4) NOT NULL,
`minTempC` smallint(4) NOT NULL,
`maxTempC` smallint(4) NOT NULL,
`skyCondition` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`precip` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`snowPotential` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`wind` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`minTempF_custom` smallint(4) DEFAULT NULL,
`maxTempF_custom` smallint(4) DEFAULT NULL,
`minTempC_custom` smallint(4) DEFAULT NULL,
`maxTempC_custom` smallint(4) DEFAULT NULL,
`baseH_custom` smallint(4) DEFAULT NULL,
`baseL_custom` smallint(4) DEFAULT NULL,
`topH_custom` smallint(4) DEFAULT NULL,
`topL_custom` smallint(4) DEFAULT NULL,
`skyCondition_custom` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
`precip_custom` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
`snowPotential_custom` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
`wind_custom` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
`icon` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`icon_custom` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
`shortrange_custom` varchar(5000) COLLATE utf8_unicode_ci DEFAULT NULL,
`longrange_custom` varchar(5000) COLLATE utf8_unicode_ci DEFAULT NULL,
`scCode` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`scUpdate` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`lastUpdate` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`skys` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`contentid`,`fulldate`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
The issue is with difference in datatype length defined and length of data being updated
Your location is varchar(10) and you are trying to insert 14 characters
You can always check if there are errors after query execution:
SHOW ERRORS;
SHOW WARNINGS;