Php 插入行laravel 5.1时出错
我在laravel模型中有以下代码:Php 插入行laravel 5.1时出错,php,mysql,laravel,orm,Php,Mysql,Laravel,Orm,我在laravel模型中有以下代码: Log::info($this->TAG.'.trySave ('.session()->getId().')', ['msg' => 'We are gonna to save an order with shopify_id: '.$this->shopify_id]); $this->save(); Log::info($this->TAG.'.trySave ('.session()->getId().')'
Log::info($this->TAG.'.trySave ('.session()->getId().')', ['msg' => 'We are gonna to save an order with shopify_id: '.$this->shopify_id]);
$this->save();
Log::info($this->TAG.'.trySave ('.session()->getId().')', ['msg' => 'SQL of insert: ', 'sql' => DB::getQueryLog()]);
Log::info($this->TAG.'.trySave ('.session()->getId().')', ['msg' => 'Order saved with shopify_id: '.$this->shopify_id]);
$orderInBD = Order::where('shopify_id', $this->shopify_id)->first();
Log::info($this->TAG.'.trySave ('.session()->getId().')', ['msg' => 'Order in BD with shopify_id: '.$orderInBD->shopify_id, 'order' => $orderInBD]);
它在日志中显示:
[2017-06-22 18:33:55] production.INFO: Order.trySave (sP9IZwqbzXLn4b6EF0pKZKrBRsyX1WEOx6M2XStM) {"msg":"We are gonna to save an order with shopify_id: 5074805714"}
[2017-06-22 18:33:55] production.INFO: Order.trySave (sP9IZwqbzXLn4b6EF0pKZKrBRsyX1WEOx6M2XStM) {"msg":"SQL of insert: ","sql":[{"query":"insert into `orders` (`shopify_id`, `user_id`, `user_id_processed_temp`, `financial_status`, `paid_at`, `accepts_marketing`, `subtotal_local`, `subtotal_eur`, `shipping_local`, `shipping_eur`, `total_local`, `total_eur`, `billing_country`, `billing_street`, `billing_phone`, `billing_zip`, `billing_province`, `billing_city`, `billing_latitude`, `billing_longitude`, `shipping_country`, `shipping_street`, `shipping_province`, `shipping_province_code`, `shipping_phone`, `shipping_city`, `shipping_zip`, `shipping_latitude`, `shipping_longitude`, `name`, `cancelled_at`, `cancel_reason`, `created_at`, `created_at_day`, `gateway`, `source_name`, `draft`, `fulfillment_status`, `updated_at`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)","bindings":[5074805714,null,1,"paid","2017-06-22T16:32:32+02:00",true,"44.00",44,"7.00",7,"51.00",51,"IT","Via n.34","334 616 6996","60041","AN","Sassoferrato",43.4292,12.8540,"IT","Via n.34","Ancona","AN","334 616 6996","","60041",43.4292,12.8540,"SITEMUERES1660269",null,null,"2017-06-22T16:32:32+02:00","2017-06-22T16:32:32+02:00","braintree","web",0,"fulfilled","2017-06-22T16:32:35+02:00"],"time":4.6}]}
[2017-06-22 18:33:55] production.INFO: Order.trySave (sP9IZwqbzXLn4b6EF0pKZKrBRsyX1WEOx6M2XStM) {"msg":"Order saved with shopify_id: 5074805714"}
[2017-06-22 18:33:55] production.INFO: Order.trySave (sP9IZwqbzXLn4b6EF0pKZKrBRsyX1WEOx6M2XStM) {"msg":"Order in BD with Shopify_ID: 779838418","order":"[object] (App\\ModelosRelacionales\\Order: {\"id\":252,\"name\":\"SITEMUERES1660269\",\"created_at\":\"2017-06-22 16:32:32\",\"created_at_day\":\"2017-06-22\",\"paid_at\":\"2017-06-22 16:32:32\",\"financial_status\":\"paid\",\"accepts_marketing\":\"1\",\"discount_code\":null,\"cancelled_at\":null,\"cancel_reason\":null,\"refunded_at\":null,\"origen\":null,\"referal\":null,\"gateway\":\"braintree\",\"discount_category\":null,\"is_code_applied\":null,\"is_shipping_code_applied\":null,\"is_shipping_native_applied\":null,\"is_compare_at_price_applied\":null,\"subtotal_local\":\"44.00\",\"subtotal_eur\":\"44.00\",\"shipping_local\":\"7.00\",\"shipping_eur\":\"7.00\",\"total_local\":\"51.00\",\"total_eur\":\"51.00\",\"discount_amount_local\":null,\"discount_amount_eur\":null,\"code_discount_amount_local\":null,\"code_discount_amount_eur\":null,\"refunded_amount_local\":null,\"refunded_amount_eur\":null,\"shipping_discount_amount_local\":null,\"shipping_discount_amount_eur\":null,\"compare_at_discount_amount_local\":null,\"compare_at_discount_amount_eur\":null,\"total_real_discount_local\":null,\"total_real_discount_eur\":null,\"shipping_country\":\"IT\",\"shipping_province\":\"Ancona\",\"shipping_province_code\":\"AN\",\"shipping_phone\":\"334\",\"shipping_city\":\"a\",\"shipping_street\":\"a\",\"shipping_zip\":\"60041\",\"shipping_latitude\":\"43.429\",\"shipping_longitude\":\"12.854\",\"billing_province\":\"AN\",\"billing_zip\":\"6004\",\"billing_phone\":\"33\",\"billing_city\":\"\",\"billing_street\":\"Via n.34\",\"billing_country\":\"IT\",\"billing_latitude\":\"43.429\",\"billing_longitude\":\"12.854\",\"customer_id\":\"0\",\"shopify_id\":\"779838418\",\"updated_at\":\"2017-06-22 16:32:35\",\"fulfillment_status\":\"fulfilled\",\"source_name\":\"web\",\"draft\":\"0\",\"deleted_at\":null,\"user_id\":null,\"user_id_processed_temp\":\"1\"})"}
如您所见,订单返回了一行,其中shopify_id不同。在插页中我有5074805714,在BD中我有:779838418
如果我在phpmyadmin中执行以下查询:
insert into `orders` (`shopify_id`, `user_id`, `user_id_processed_temp`, `financial_status`, `paid_at`, `accepts_marketing`, `subtotal_local`, `subtotal_eur`, `shipping_local`, `shipping_eur`, `total_local`, `total_eur`, `billing_country`, `billing_street`, `billing_phone`, `billing_zip`, `billing_province`, `billing_city`, `billing_latitude`, `billing_longitude`, `shipping_country`, `shipping_street`, `shipping_province`, `shipping_province_code`, `shipping_phone`, `shipping_city`, `shipping_zip`, `shipping_latitude`, `shipping_longitude`, `name`, `cancelled_at`, `cancel_reason`, `created_at`, `created_at_day`, `gateway`, `source_name`, `draft`, `fulfillment_status`, `updated_at`) values (5074805714, null, 1, "paid", "2017-06-22T16:09:31+02:00", true, "24.00", 24, "7.00", 7, "31.00", 31, "es", "Calle", "766", "0311", "a", "busot", 38.4804, -0.4210, "ES", "calle", "a", "a", "6765", "busot", "03111", 38.4804688, -0.4210394, "SITEMUERES1660091", null, null, "2017-06-22T16:09:31+02:00", "2017-06-22T16:09:31+02:00", "braintree", "web", 0, "fulfilled", "2017-06-22T16:09:37+02:00")
它很好用
字段结构shopify_id为bigint(20)
编辑1
如果我这样做:
它很好用
编辑2
如果我这样做:
它也很好用。我知道Laravel可以支持大的数字,因为在生产中同样的应用程序做得很好
编辑3
如果我这样做:
$this->shopify_id = strval($json['id'])
它起作用了
会发生什么情况?模型中的
$filleble
数组中是否有shopfify\u id
?不,我在filleble数组中没有任何字段。是否使用多个数据库连接?只有一个连接
$this->shopify_id -= 5000000000;
$this->save();
$this->shopify_id = strval($json['id'])