mysql

How to seed pivot table in Laravel 5.4?

穿精又带淫゛_ 提交于 2021-02-08 13:04:41
问题 I am following a tutorial called Incremental API in laracasts by Jeffrey Way. There is a different coding between Laravel 4 faker class seeding and laravel 5.4. I still followed the same code lines from the tutorials "Seeders Reloaded". Now, I am stuck with "Class LessonTagTableSeeder does not exist" TagTableSeeder class TagsTableSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { $faker = Faker::create('App\Tag'); for($i=1; $i <= 10; $i++) { DB:

Springframework.dao.InvalidDataAccessResourceUsageException hibernate.SQLGrammarException MySQLSyntaxErrorException

笑着哭i 提交于 2021-02-08 12:57:18
问题 I'm breaking my head trying to find out what's wrong here. I'm working on a schema: It has a Story entity (table: stories) and I'm trying to add a column to this stories.portofoliotype_id which is a foreign key to PortfolioType (table: portofoliotypes) . I think I have the annotations right, I even logged MySQL queries, it gets the following query, which is correct. I'm trying to create a new story: insert into stories(backlog_id, description, iteration_id, name, parent_id,portfoliotype_id,

Is naming tables september_2010 acceptable and efficient for large data sets dependent on time?

三世轮回 提交于 2021-02-08 12:49:33
问题 I need to store about 73,200 records per day consisting of 3 points of data: id, date, and integer. Some members of my team suggest creating tables using month's as the table name (september_2010), while others are suggesting having one table with lots of data in it... Any suggestions on how to deal with this amount of data? Thanks. ========== Thank you to all the feedback. 回答1: I recommend against that. I call this antipattern Metadata Tribbles . It creates multiple problems: You need to

MySQL分表自增ID解决方案

心不动则不痛 提交于 2021-02-08 12:42:42
当我们对MySQL进行分表操作后,将不能依赖MySQL的自动增量来产生唯一ID了,因为数据已经分散到多个表中。 应尽量避免使用自增IP来做为主键,为数据库分表操作带来极大的不便。 在postgreSQL、oracle、db2数据库中有一个特殊的特性---sequence。 任何时候数据库可以根据当前表中的记录数大小和步长来获取到该表下一条记录数。然而,MySQL是没有这种序列对象的。 可以通过下面的方法来实现sequence特性产生唯一ID: 1. 通过MySQL表生成ID 在《 关于MySQL分表操作的研究 》提到了一种方法: 对于插入也就是insert操作,首先就是获取唯一的id了,就需要一个表来专门创建id,插入一条记录,并获取最后插入的ID。代码如下: CREATE TABLE `ttlsa_com`.`create_id` ( `id` BIGINT( 20 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ) ENGINE = MYISAM 也就是说,当我们需要插入数据的时候,必须由这个表来产生id值,我的php代码的方法如下: <?php function get_AI_ID() { $sql = "insert into create_id (id) values('')"; $this->db->query($sql); return

Inserting variable into SQL query from Java

核能气质少年 提交于 2021-02-08 12:20:58
问题 How do you insert variables into an SQL Query? This is what I have so far ... public String getBugList(int amount) { Connection con = DatabaseConnection.getConnection(); try (PreparedStatement ps = con.prepareStatement("SELECT submitter, report FROM bugs_log ORDER BY id DESC limit )) } I'm trying to get "amount" bugs to list. So if I input 2, then only the top 2 will get listed. 回答1: Try this code: public String getBugList(int amount) { Connection con = DatabaseConnection.getConnection();

Inserting variable into SQL query from Java

本小妞迷上赌 提交于 2021-02-08 12:20:00
问题 How do you insert variables into an SQL Query? This is what I have so far ... public String getBugList(int amount) { Connection con = DatabaseConnection.getConnection(); try (PreparedStatement ps = con.prepareStatement("SELECT submitter, report FROM bugs_log ORDER BY id DESC limit )) } I'm trying to get "amount" bugs to list. So if I input 2, then only the top 2 will get listed. 回答1: Try this code: public String getBugList(int amount) { Connection con = DatabaseConnection.getConnection();

MySQL replace all whitespaces with -

半腔热情 提交于 2021-02-08 12:19:47
问题 how could i remove ALL whitespaces from a row? I see here alot of same question but all answers ar to use replace option. Replace will work only to strip one spaces, not all. ex: a b c to become a-b-c Thanks. 回答1: This can be achieved with the following MySQL Function: SELECT REPLACE( table.field, ' ', '-' ) FROM table; This should replace all the whitespace to a - 回答2: Try this replace('a b c',' ','-') 回答3: update image set path = REPLACE( image.path, ' ', '-' ) where path like '% %' if you

MySQL replace all whitespaces with -

喜你入骨 提交于 2021-02-08 12:18:54
问题 how could i remove ALL whitespaces from a row? I see here alot of same question but all answers ar to use replace option. Replace will work only to strip one spaces, not all. ex: a b c to become a-b-c Thanks. 回答1: This can be achieved with the following MySQL Function: SELECT REPLACE( table.field, ' ', '-' ) FROM table; This should replace all the whitespace to a - 回答2: Try this replace('a b c',' ','-') 回答3: update image set path = REPLACE( image.path, ' ', '-' ) where path like '% %' if you

MySQL : strange LENGTH() behaviour on utf8 string

偶尔善良 提交于 2021-02-08 12:18:52
问题 I am doing unit tests on requests generators, and I get in trouble with LENGTH function. I have 2 requests that follows each other : SHOW VARIABLES LIKE '%character%' Returns the following result : array(8) { [0] => array(2) { 'Variable_name' => string(20) "character_set_client" 'Value' => string(4) "utf8" } [1] => array(2) { 'Variable_name' => string(24) "character_set_connection" 'Value' => string(4) "utf8" } [2] => array(2) { 'Variable_name' => string(22) "character_set_database" 'Value' =

MySQL : strange LENGTH() behaviour on utf8 string

旧巷老猫 提交于 2021-02-08 12:18:32
问题 I am doing unit tests on requests generators, and I get in trouble with LENGTH function. I have 2 requests that follows each other : SHOW VARIABLES LIKE '%character%' Returns the following result : array(8) { [0] => array(2) { 'Variable_name' => string(20) "character_set_client" 'Value' => string(4) "utf8" } [1] => array(2) { 'Variable_name' => string(24) "character_set_connection" 'Value' => string(4) "utf8" } [2] => array(2) { 'Variable_name' => string(22) "character_set_database" 'Value' =