(1054, "Unknown column 'user' in 'field list'") django用户注册报错

想用django实现注册功能,但是会出现这样的错误
看好多博客说跟数据库名字有关,也看不懂,改不明白啊,改了一下午了,
大佬们!路过帮帮忙!

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
大神们求助,Unknown column 'userName' in 'field list'

日志: 严重: Servlet.service() for servlet springMVC threw exception com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'userName' in 'field list' at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at com.mysql.jdbc.Util.handleNewInstance(Util.java:403) at com.mysql.jdbc.Util.getInstance(Util.java:378) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1031) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3361) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3295) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1852) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1975) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2476) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1583) at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:988) at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:41) at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:66) at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:45) at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:108) at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:75) at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:145) at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:134) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:355) at com.sun.proxy.$Proxy12.insert(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:237) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:79) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:40) at com.sun.proxy.$Proxy16.addUser(Unknown Source) at com.fu.ssm.daoimpl.UserDaoimpl.addUser(UserDaoimpl.java:34) at com.fu.ssm.servicesimpl.UserServiceimpl.addUser(UserServiceimpl.java:28) at com.fu.ssm.controller.UserController.addUser(UserController.java:37) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:745) 我写的sql <!-- 插入一条数据 --> <insert id="addUser" parameterType="com.fu.ssm.pojo.User" keyProperty="id"> insert into user (userName,password,age,remark) values (#{userName,jdbcType=VARCHAR},#{password,jdbcType=VARCHAR},#{age,jdbcType=INTEGER},#{remark,jdbcType=VARCHAR}) </insert>

mysql 插入数据出现Unknown column 'aaaaa' in 'field list'

public class DBConnection { public static final String url = "jdbc:mysql://localhost:3306/news"; public static final String name = "com.mysql.jdbc.Driver"; public static final String user = "root"; public static final String password = "987321"; public Connection conn = null; public Statement pst = null; public DBConnection(String sql) { try { Class.forName(name); conn = DriverManager.getConnection(url, user, password); pst = conn.createStatement(); pst.execute(sql); } catch (Exception e) { e.printStackTrace(); } } public void close() { try { this.conn.close(); this.pst.close(); } catch (SQLException e) { e.printStackTrace(); } } public static void main(String[] args) { String s1 = "aaaaa"; String s2 = "bbbbb"; String s3= "cccccccccccccccccccccccccccccc"; DBConnection conn = new DBConnection("insert into newscontent(newsType,newsTitle,newsContent) value("+s1+","+s2+","+s3+")"); conn.close(); } }

mysql报错Unknown column

本人小白(c币有限,求帮忙!!),在搭建ssh框架时遇到如题的问题,在网上也没有找到解决方案,求大神帮帮忙,在线等: 建表语句: ``` CREATE TABLE `user` ( `userId` varchar(100) NOT NULL, `userName` varchar(255) DEFAULT NULL, `userPassword` varchar(255) DEFAULT NULL, `userCreateTime` varchar(255) DEFAULT NULL, `userUpdateTime` varchar(255) DEFAULT NULL, `userStatus` varchar(255) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ---------------------------- -- Records of user -- ---------------------------- INSERT INTO `user` VALUES ('001', 'admin', '123456', null, null, null); ``` 实体类: ``` @Entity @Table(name="USER") public class User { private String userid;// private String user_name;// private String user_password;// private String user_status;// private String user_create_time;// private String user_update_time;// @Id @Column(name="userId") public String getUserid() { return userid; } public void setUserid(String userid) { this.userid = userid; } @Column(name="userName") public String getUser_name() { return user_name; } public void setUser_name(String user_name) { this.user_name = user_name; } @Column(name="userPassword") public String getUser_password() { return user_password; } public void setUser_password(String user_password) { this.user_password = user_password; } @Column(name="userStatus") public String getUser_status() { return user_status; } public void setUser_status(String user_status) { this.user_status = user_status; } @Column(name="userCreateTime") public String getUser_create_time() { return user_create_time; } public void setUser_create_time(String user_create_time) { this.user_create_time = user_create_time; } @Column(name="userUpdateTime") public String getUser_update_time() { return user_update_time; } public void setUser_update_time(String user_update_time) { this.user_update_time = user_update_time; } ``` 用的ssh框架,查询时打印的sql语句正常,但报错, 错误代码如下: ``` Hibernate: select user0_.userId as userId1_7_, user0_.userCreateTime as userCrea2_7_, user0_.userName as userName3_7_, user0_.userPassword as userPass4_7_, user0_.userStatus as userStat5_7_, user0_.userUpdateTime as userUpda6_7_ from user user0_ where user0_.userName='admin' 2017-09-01 12:03:34,397 [http-nio-8080-exec-28] WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - SQL Error: 1054, SQLState: 42S22 2017-09-01 12:03:34,397 [http-nio-8080-exec-28] ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - Unknown column 'user0_.userId' in 'field list' 2017-09-01 12:03:34,578 [http-nio-8080-exec-28] WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - SQL Warning Code: 1054, SQLState: 42S22 2017-09-01 12:03:34,578 [http-nio-8080-exec-28] WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] - Unknown column 'user0_.userId' in 'field list' ```

MySQL在cmd时更改密码时总是出现unknown column'user' in'where clause'

换了一个版本的navicat,连接MySQL把密码忘了 在更改密码的时候已经用的无密登录但是在后面一直有问题 代码 mysql> UPDATE mysql.user SET authentication_string='123456' WHERE user='root' and host='localhost'; ERROR 1054 (42S22): Unknown column 'user' in 'where clause' mysql> UPDATE mysql.user SET password=PASSWORD('123456')where User='root'; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('ROOT')where User='root'' at line 1 另外在查询密码的时候也有问题 代码 mysql> select host,user,password from mysql.user; ERROR 1054 (42S22): Unknown column 'host' in 'field list'

在测试sql注入时,出现 Unknown column 'id' in 'where clause'错误,试了很多修改方法都不行

![图片说明](https://img-ask.csdn.net/upload/202002/04/1580746566_81510.png)![图片说明](https://img-ask.csdn.net/upload/202002/04/1580746575_798099.png)![图片说明](https://img-ask.csdn.net/upload/202002/04/1580746583_259652.png) ``` package com.bjsxt.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; /*测试SQL执行语句,以及SQL注入问题 *试了很多修改方法都不行,比如:我在eclipse中把id改成整型int...,或把"5"的引号去掉,都不行。(String id = "5 or 1=1";是测试恶意数据的) * */ public class Demo02 { public static void main(String[] args){ try { //加载驱动类 Class.forName("com.mysql.jdbc.Driver"); //建立连接 Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/testjdbc","root","admin"); Statement stmt = conn.createStatement(); ** **_ //测试sql注入 _**** String id = "5 or 1=1"; String sql = "delete from t_user where id="+id; stmt.execute(sql); /*试了很多修改方法都不行,比如:我在eclipse中把id改成整型int...,或把"5"的引号去掉,都不行。(String id = "5 or 1=1";是测试恶意数据的) 都不行!!* */ } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } ```

mySql query.Unknown列''in'字段列表'出错

<div class="post-text" itemprop="text"> <p>I have a database with 4 columns <code>Date</code>,<code>to</code>,<code>message</code>,<code>from</code> one of <code>date</code> format and all <code>varchar</code>. Following is the error that i am getting:</p><p> Error: Database Error Unknown column 'anything i enter into the form's first field' in 'field list'. Here is my code:</p> <p>form:</p> <pre><code>&lt;form method='post' name:mail&gt; &lt;label&gt; &lt;p&gt; Send to Username:&lt;p&gt; &lt;/label&gt; &lt;input type="text" name="user" hint="Enter username" id="user" placeholder = "Name" &gt; &lt;/label&gt;&lt;p&gt; Message: &lt;p&gt; &lt;label&gt; &lt;textarea name="message" cols="40" rows="5"&gt; &lt;/textarea&gt;&lt;br&gt; &lt;input type="submit" name="submit" id="submit" value="Send" /&gt; </code></pre> <p>I know i should not have used $POST_[] directly into the query but i am just testing it.</p><p> php code:</p> <pre><code>&lt;?php $con = mysqli_connect("localhost","","",""); if (!$con) { echo" Not connected to database"; die('Could not connect: ' . mysqli_error()); } if(isset($_POST['submit'])) { $username1=$_SESSION["username"]; $sql = "INSERT INTO anengine_dbase.mail(`Date`,`to`,`message`,`from`) VALUES (CURDATE(),`$_POST[user]`, `$_POST[message]`,`$username1`)"; $xy=mysqli_query($con,$sql); if (!$xy) { die('Database Error ' . mysqli_error($con)); } echo "message successfully recorded "; } ?&gt; </code></pre> </div>

mybatis出现了很奇怪的问题

``` ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'card_id' in 'field list' ### The error may exist in com/ershou/mapper/UserMapper.xml ### The error may involve com.ershou.mapper.UserMapper.selectByExample-Inline ### The error occurred while setting parameters ### SQL: select card_id, password, college, grade, sex, status, trueName, image from user WHERE ( card_id = ? and password = ? ) ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'card_id' in 'field list' ; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'card_id' in 'field list'] with root cause com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'card_id' in 'field list' ``` 提示我的card_id 数据库不认识,但是我的数据库就是这样定义的啊 我用的也是generator自动生成的代码 CREATE TABLE `user` ( `card_id` varchar(20) NOT NULL, `password` varchar(20) DEFAULT NULL, `college` varchar(200) DEFAULT NULL, `grade` varchar(200) DEFAULT NULL, `sex` int(2) DEFAULT '1', `status` int(2) DEFAULT '1', `trueName` varchar(20) DEFAULT NULL, `image` varchar(50) DEFAULT NULL, PRIMARY KEY (`card_id`) ) 看一下mybatis的XXXMapper.xml文件 <resultMap id="BaseResultMap" type="com.ershou.entity.User" > <id column="card_id" property="cardId" jdbcType="VARCHAR" /> <result column="password" property="password" jdbcType="VARCHAR" /> <result column="college" property="college" jdbcType="VARCHAR" /> <result column="grade" property="grade" jdbcType="VARCHAR" /> <result column="sex" property="sex" jdbcType="INTEGER" /> <result column="status" property="status" jdbcType="INTEGER" /> <result column="trueName" property="truename" jdbcType="VARCHAR" /> <result column="image" property="image" jdbcType="VARCHAR" /> </resultMap> <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.ershou.entity.UserExample" > select <if test="distinct" > distinct </if> <include refid="Base_Column_List" /> from user <if test="_parameter != null" > <include refid="Example_Where_Clause" /> </if> <if test="orderByClause != null" > order by ${orderByClause} </if> </select> 哪里出错了 见鬼了 求大神

PDOException::(“SQLSTATE [42S22]:未找到列:1054'字段列表'中的未知列'问题'”)

<div class="post-text" itemprop="text"> <p>After <code>php artisan db:seed</code> I am getting error:</p> <pre><code>1 PDOException::("SQLSTATE[42S22]: Column not found: 1054 Unknown column 'question' in 'field list'") F:\Projects\php ealtimeApp\vendor\laravel\framework\src\Illuminate\Database\Connection.php:452 2 PDO::prepare("insert into `replies` (`body`, `question`, `user_id`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?)")" </code></pre> <p>Here is my Github repo: <a href="https://github.com/hevzy86/realtimeApp" rel="nofollow noreferrer">https://github.com/hevzy86/realtimeApp</a></p> </div>

mybatis+mysql selectList 出错问题

mybatis初学者,如题: xml中sql语句 ``` <select id="findUserByName" parameterType="java.lang.String" resultType="org.model.User"> SELECT * FROM t_user WHERE login_name LIKE "%"#{value}"%" </select> ``` 测试程序 ``` @Test public void deleteUser() throws IOException{ //mybatis配置文件 String resource = "SqlMapConfig.xml"; InputStream input = Resources.getResourceAsStream(resource); //创建会话工厂 SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(input); //通过工厂得到SqlSession SqlSession sqlSession = sqlSessionFactory.openSession(); //通过session操作数据库 //第一个参数:statement的id,等于=namespace+statementId //第二个参赛:指定和映射文件中所匹配的parameterType类型的参数 List<User> users = sqlSession.selectList("test.findUserByName", "admina"); for(User user:users){ System.out.println(user); String loginName = user.getLoginName(); System.out.println(loginName); } sqlSession.close(); } ``` 运行问题 ![图片说明](https://img-ask.csdn.net/upload/201507/05/1436082413_209438.png) 在数据库中运行sql此项是有值的,我是根据此项查的,为什么查询成功了但是其他项都有值,就此项无值呢,求解。

CodeIgniter:发生数据库错误错误号:1054

<div class="post-text" itemprop="text"> <p>I'm getting this error when working with CodeIgniter:</p> <pre><code>A Database Error Occurred Error Number: 1054 Unknown column 'data' in 'field list' SELECT `data` FROM `ci_sessions` WHERE `id` = '4j5h21j1us9nhah0qc1hqmmmevb1oa2f' AND `ip_address` = '::1' Filename: C:/wamp64/www/life/app/delta/system/database/DB_driver.php Line Number: 691 </code></pre> <p>It's so frustrating. I've tried everything I know.</p> <p>Here is the part of my controller i think the error is coming from</p> <pre><code>public function index() { if ($this-&gt;session-&gt;userdata('logged_in') == TRUE) { if ($this-&gt;session-&gt;userdata('usr_access_level') == 1) { redirect('users'); } else { redirect('me'); } } $data['login_fail'] = TRUE; $this-&gt;load-&gt;view('common/login_header'); $this-&gt;load-&gt;view('admin/signin', $data); $this-&gt;load-&gt;view('common/footer'); } else { $data = array( 'usr_id' =&gt; $row-&gt;usr_id, 'acc_id' =&gt; $row-&gt;acc_id, 'user_name' =&gt; $row-&gt;user_name, 'usr_access_level' =&gt; $row-&gt;usr_access_level, 'logged_in' =&gt; TRUE ); // Save data to session $this-&gt;session-&gt;set_userdata($data); if ($data['usr_access_level'] == 2) { redirect('me'); } elseif ($data['usr_access_level'] == 1) { redirect('users'); } else { redirect('me'); } } </code></pre> <p>Here is the Model for the controller </p> <pre><code>class _model extends CI_Model </code></pre> <p>{</p> <pre><code>function __construct() { parent::__construct(); } public function does_user_exist($email) { $this-&gt;db-&gt;where('user_name', $email); $query = $this-&gt;db-&gt;get('users'); return $query; } </code></pre> <p>}</p> </div>

SQLSTATE [42S22]:未找到列:1054 Laravel中“字段列表”中的未知列“会话”

<div class="post-text" itemprop="text"> <p>I am getting a strange error! I did not create any field named 'session' in <strong><em>database</em></strong> and there is no such field in <strong><em>model</em></strong> named 'session'. I used <strong><em>SoftDeletes()</em></strong> in the model but whenever I am trying to insert data I get an error with this message: </p> <p><strong>SQLSTATE[42S22]: Column not found: 1054 Unknown column 'session' in 'field list'</strong> </p> <p>Here is the model:</p> <pre><code>&lt;?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class Article extends Model { use SoftDeletes; protected $fillable = [ 'user_id', 'headline', 'summary', 'body', 'status', 'cover_image', 'image_caption', 'image_credit', 'cover_video', 'video_caption', 'video_credit', 'category', 'meta', 'tags', ]; protected $dates = ['deleted_at']; public function user() { return $this-&gt;belongsTo('App\User'); } } </code></pre> <p>Here is the database: <img src="https://i.stack.imgur.com/iNYXs.jpg"> <a href="https://i.stack.imgur.com/iNYXs.jpg" rel="nofollow noreferrer">enter image description here</a></p> <p>Here is the controller:</p> <pre><code>public function store(Request $request) { $article = new Article; $article-&gt;user_id = $request-&gt;user_id; $article-&gt;headline = $request-&gt;headline; $article-&gt;summary = $request-&gt;summary; $article-&gt;body = $request-&gt;body; $article-&gt;status = $request-&gt;status; $article-&gt;session = $request-&gt;session; $article-&gt;category = $request-&gt;category; $article-&gt;meta = $request-&gt;meta; $article-&gt;tags = $request-&gt;tags; //dd($request-&gt;session()); $article-&gt;save(); return back()-&gt;with('success', 'Article Successfully Added!'); } </code></pre> <p>How can I solve this problem? </p> </div>

Codeigniter 3 + Tank auth抛出错误:'字段列表'中的未知列'数据'

<div class="post-text" itemprop="text"> <p>Can you help me please with authentication in Codeigniter? I start with CI yesterday so I am little confused. I found <a href="https://konyukhov.com/soft/tank_auth/" rel="nofollow">Tank auth library</a>, but it seems it is not compatible with CI3. It throws me an error: "Unknown column 'data' in 'field list'" from libraries/Session/drivers/Session_database_driver.php Session library expects the field name data in ci_session table. My ci_session table comes from Tank auth download and there is user_data field instead. What can I do? Or is there a better authentication library for CI3? I wolud like to find lib with authentication + authorisation. </p> </div>

一种避免串联字符串上的SQL注入的简单方法

<div class="post-text" itemprop="text"> <p>I was trying to think in a simple way to avoid SQL Injection without using any libraries. Just a plain old sql string that I may concatenate parameters as I see fit and pass the whole query to the DB. No PDO, no prepared queries, no escaped strings. </p> <p>I think the reasons why I don't want to use these aproaches are not relevant to this question, once it would turn it into a viewpoint debate, which isn't what SO is about.</p> <p>In my view the only really problematic case is of names search as it would have to pass it to "LIKE '%:name%', once I can easily check validity for integer, dates and other kinds of parameters. So I came around this function here:</p> <pre><code>function strHasSQLReservedWords($str) { $str = strtoupper($str); $keywords = array("ABSOLUTE", "ACTION", "ADD", "AFTER", "ALL", "ALLOCATE", "ALTER", "AND", "ANY", "ARE", "ARRAY", "AS", "ASC", "ASENSITIVE", "ASSERTION", "ASYMMETRIC", "AT", "ATOMIC", "AUTHORIZATION", "AVG", "BEFORE", "BEGIN", "BETWEEN", "BIGINT", "BINARY", "BIT", "BIT_LENGTH", "BLOB", "BOOLEAN", "BOTH", "BREADTH", "BY", "CALL", "CALLED", "CASCADE", "CASCADED", "CASE", "CAST", "CATALOG", "CHAR", "CHARACTER", "CHARACTER_LENGTH", "CHAR_LENGTH", "CHECK", "CLOB", "CLOSE", "COALESCE", "COLLATE", "COLLATION", "COLUMN", "COMMIT", "CONDITION", "CONNECT", "CONNECTION", "CONSTRAINT", "CONSTRAINTS", "CONSTRUCTOR", "CONTAINS", "CONTINUE", "CONVERT", "CORRESPONDING", "COUNT", "CREATE", "CROSS", "CUBE", "CURRENT", "CURRENT_DATE", "CURRENT_DEFAULT_TRANSFORM_GROUP", "CURRENT_PATH", "CURRENT_ROLE", "CURRENT_TIME", "CURRENT_TIMESTAMP", "CURRENT_TRANSFORM_GROUP_FOR_TYPE", "CURRENT_USER", "CURSOR", "CYCLE", "DATA", "DATE", "DAY", "DEALLOCATE", "DEC", "DECIMAL", "DECLARE", "DEFAULT", "DEFERRABLE", "DEFERRED", "DELETE", "DEPTH", "DEREF", "DESC", "DESCRIBE", "DESCRIPTOR", "DETERMINISTIC", "DIAGNOSTICS", "DISCONNECT", "DISTINCT", "DO", "DOMAIN", "DOUBLE", "DROP", "DYNAMIC", "EACH", "ELEMENT", "ELSE", "ELSEIF", "END", "EQUALS", "ESCAPE", "EXCEPT", "EXCEPTION", "EXEC", "EXECUTE", "EXISTS", "EXIT", "EXTERNAL", "EXTRACT", "FALSE", "FETCH", "FILTER", "FIRST", "FLOAT", "FOR", "FOREIGN", "FOUND", "FREE", "FROM", "FULL", "FUNCTION", "GENERAL", "GET", "GLOBAL", "GO", "GOTO", "GRANT", "GROUP", "GROUPING", "HANDLER", "HAVING", "HOLD", "HOUR", "IDENTITY", "IF", "IMMEDIATE", "IN", "INDICATOR", "INITIALLY", "INNER", "INOUT", "INPUT", "INSENSITIVE", "INSERT", "INT", "INTEGER", "INTERSECT", "INTERVAL", "INTO", "IS", "ISOLATION", "ITERATE", "JOIN", "KEY", "LANGUAGE", "LARGE", "LAST", "LATERAL", "LEADING", "LEAVE", "LEFT", "LEVEL", "LIKE", "LOCAL", "LOCALTIME", "LOCALTIMESTAMP", "LOCATOR", "LOOP", "LOWER", "MAP", "MATCH", "MAX", "MEMBER", "MERGE", "METHOD", "MIN", "MINUTE", "MODIFIES", "MODULE", "MONTH", "MULTISET", "NAMES", "NATIONAL", "NATURAL", "NCHAR", "NCLOB", "NEW", "NEXT", "NO", "NONE", "NOT", "NULL", "NULLIF", "NUMERIC", "OBJECT", "OCTET_LENGTH", "OF", "OLD", "ON", "ONLY", "OPEN", "OPTION", "OR", "ORDER", "ORDINALITY", "OUT", "OUTER", "OUTPUT", "OVER", "OVERLAPS", "PAD", "PARAMETER", "PARTIAL", "PARTITION", "PATH", "POSITION", "PRECISION", "PREPARE", "PRESERVE", "PRIMARY", "PRIOR", "PRIVILEGES", "PROCEDURE", "PUBLIC", "RANGE", "READ", "READS", "REAL", "RECURSIVE", "REF", "REFERENCES", "REFERENCING", "RELATIVE", "RELEASE", "REPEAT", "RESIGNAL", "RESTRICT", "RESULT", "RETURN", "RETURNS", "REVOKE", "RIGHT", "ROLE", "ROLLBACK", "ROLLUP", "ROUTINE", "ROW", "ROWS", "SAVEPOINT", "SCHEMA", "SCOPE", "SCROLL", "SEARCH", "SECOND", "SECTION", "SELECT", "SENSITIVE", "SESSION", "SESSION_USER", "SET", "SETS", "SIGNAL", "SIMILAR", "SIZE", "SMALLINT", "SOME", "SPACE", "SPECIFIC", "SPECIFICTYPE", "SQL", "SQLCODE", "SQLERROR", "SQLEXCEPTION", "SQLSTATE", "SQLWARNING", "START", "STATE", "STATIC", "SUBMULTISET", "SUBSTRING", "SUM", "SYMMETRIC", "SYSTEM", "SYSTEM_USER", "TABLE", "TABLESAMPLE", "TEMPORARY", "THEN", "TIME", "TIMESTAMP", "TIMEZONE_HOUR", "TIMEZONE_MINUTE", "TO", "TRAILING", "TRANSACTION", "TRANSLATE", "TRANSLATION", "TREAT", "TRIGGER", "TRIM", "TRUE", "UNDER", "UNDO", "UNION", "UNIQUE", "UNKNOWN", "UNNEST", "UNTIL", "UPDATE", "UPPER", "USAGE", "USER", "USING", "VALUE", "VALUES", "VARCHAR", "VARYING", "VIEW", "WHEN", "WHENEVER", "WHERE", "WHILE", "WINDOW", "WITH", "WITHIN", "WITHOUT", "WORK", "WRITE", "YEAR", "ZONE"); foreach($keywords as $keyword) if (strpos($str, $keyword) &gt;=0) return true; return false; } </code></pre> <p>so I would use something like:</p> <pre><code>$name = // get name from request; $sql = 'select * from mytable where name = :name'; if (!strHasSQLReservedWords($name)) { $sql = str_replace(":name", $name, $sql); $result = $DBProviderSQLExecuteFunction($sql); } </code></pre> <p>Anyone sees a way a SQL injection could pass through this validation for name parameters ? if yes, is there any way to enhance it so I can use it this way ?</p> <p>please forget for now names like O'Hara as they could be easily validated. </p> <p><strong>Edit</strong></p> <p>Well I don't want to say my reasons 'cause if I told them to you I'll start a discussion about their validity, and probably a moderator will intervene as that's not what SO is for. But if you insist I can open a private talk and explain them to you. But I really don't think that's relevant.</p> <p>About apostrophes, I'm not very worried with them because this system is used in a country where apostrophes aren't common. I checked my whole DB (26.733 names) and there isn't one single name that has an apostrophe. That's because names in this system came directly from A3 tokens and there are no special characters in the name field. Just plain letters. So I'm really confident I won't have problems with it, and I can fix any if they came.</p> <p>So... about bug fixing my function, what if I divide the name by spaces and compare whole words with the reserved words list ? I can exclude MAX function as it won't have any major drawback AFAIU. Is there another function you see that can be a whole name ? Nobody's called OR or AND. :D</p> <p>So based on that I enhanced the function to this:</p> <pre><code>function strHasSQLReservedWords($str) { $str = preg_replace('/\s+/', ' ',$row['message']); $arr = explode(" ", strtoupper($str)); //"MAX", $keywords = array("ABSOLUTE", "ACTION", "ADD", "AFTER", "ALL", "ALLOCATE", "ALTER", "AND", "ANY", "ARE", "ARRAY", "AS", "ASC", "ASENSITIVE", "ASSERTION", "ASYMMETRIC", "AT", "ATOMIC", "AUTHORIZATION", "AVG", "BEFORE", "BEGIN", "BETWEEN", "BIGINT", "BINARY", "BIT", "BIT_LENGTH", "BLOB", "BOOLEAN", "BOTH", "BREADTH", "BY", "CALL", "CALLED", "CASCADE", "CASCADED", "CASE", "CAST", "CATALOG", "CHAR", "CHARACTER", "CHARACTER_LENGTH", "CHAR_LENGTH", "CHECK", "CLOB", "CLOSE", "COALESCE", "COLLATE", "COLLATION", "COLUMN", "COMMIT", "CONDITION", "CONNECT", "CONNECTION", "CONSTRAINT", "CONSTRAINTS", "CONSTRUCTOR", "CONTAINS", "CONTINUE", "CONVERT", "CORRESPONDING", "COUNT", "CREATE", "CROSS", "CUBE", "CURRENT", "CURRENT_DATE", "CURRENT_DEFAULT_TRANSFORM_GROUP", "CURRENT_PATH", "CURRENT_ROLE", "CURRENT_TIME", "CURRENT_TIMESTAMP", "CURRENT_TRANSFORM_GROUP_FOR_TYPE", "CURRENT_USER", "CURSOR", "CYCLE", "DATA", "DATE", "DAY", "DEALLOCATE", "DEC", "DECIMAL", "DECLARE", "DEFAULT", "DEFERRABLE", "DEFERRED", "DELETE", "DEPTH", "DEREF", "DESC", "DESCRIBE", "DESCRIPTOR", "DETERMINISTIC", "DIAGNOSTICS", "DISCONNECT", "DISTINCT", "DO", "DOMAIN", "DOUBLE", "DROP", "DYNAMIC", "EACH", "ELEMENT", "ELSE", "ELSEIF", "END", "EQUALS", "ESCAPE", "EXCEPT", "EXCEPTION", "EXEC", "EXECUTE", "EXISTS", "EXIT", "EXTERNAL", "EXTRACT", "FALSE", "FETCH", "FILTER", "FIRST", "FLOAT", "FOR", "FOREIGN", "FOUND", "FREE", "FROM", "FULL", "FUNCTION", "GENERAL", "GET", "GLOBAL", "GO", "GOTO", "GRANT", "GROUP", "GROUPING", "HANDLER", "HAVING", "HOLD", "HOUR", "IDENTITY", "IF", "IMMEDIATE", "IN", "INDICATOR", "INITIALLY", "INNER", "INOUT", "INPUT", "INSENSITIVE", "INSERT", "INT", "INTEGER", "INTERSECT", "INTERVAL", "INTO", "IS", "ISOLATION", "ITERATE", "JOIN", "KEY", "LANGUAGE", "LARGE", "LAST", "LATERAL", "LEADING", "LEAVE", "LEFT", "LEVEL", "LIKE", "LOCAL", "LOCALTIME", "LOCALTIMESTAMP", "LOCATOR", "LOOP", "LOWER", "MAP", "MATCH", "MEMBER", "MERGE", "METHOD", "MIN", "MINUTE", "MODIFIES", "MODULE", "MONTH", "MULTISET", "NAMES", "NATIONAL", "NATURAL", "NCHAR", "NCLOB", "NEW", "NEXT", "NO", "NONE", "NOT", "NULL", "NULLIF", "NUMERIC", "OBJECT", "OCTET_LENGTH", "OF", "OLD", "ON", "ONLY", "OPEN", "OPTION", "OR", "ORDER", "ORDINALITY", "OUT", "OUTER", "OUTPUT", "OVER", "OVERLAPS", "PAD", "PARAMETER", "PARTIAL", "PARTITION", "PATH", "POSITION", "PRECISION", "PREPARE", "PRESERVE", "PRIMARY", "PRIOR", "PRIVILEGES", "PROCEDURE", "PUBLIC", "RANGE", "READ", "READS", "REAL", "RECURSIVE", "REF", "REFERENCES", "REFERENCING", "RELATIVE", "RELEASE", "REPEAT", "RESIGNAL", "RESTRICT", "RESULT", "RETURN", "RETURNS", "REVOKE", "RIGHT", "ROLE", "ROLLBACK", "ROLLUP", "ROUTINE", "ROW", "ROWS", "SAVEPOINT", "SCHEMA", "SCOPE", "SCROLL", "SEARCH", "SECOND", "SECTION", "SELECT", "SENSITIVE", "SESSION", "SESSION_USER", "SET", "SETS", "SIGNAL", "SIMILAR", "SIZE", "SMALLINT", "SOME", "SPACE", "SPECIFIC", "SPECIFICTYPE", "SQL", "SQLCODE", "SQLERROR", "SQLEXCEPTION", "SQLSTATE", "SQLWARNING", "START", "STATE", "STATIC", "SUBMULTISET", "SUBSTRING", "SUM", "SYMMETRIC", "SYSTEM", "SYSTEM_USER", "TABLE", "TABLESAMPLE", "TEMPORARY", "THEN", "TIME", "TIMESTAMP", "TIMEZONE_HOUR", "TIMEZONE_MINUTE", "TO", "TRAILING", "TRANSACTION", "TRANSLATE", "TRANSLATION", "TREAT", "TRIGGER", "TRIM", "TRUE", "UNDER", "UNDO", "UNION", "UNIQUE", "UNKNOWN", "UNNEST", "UNTIL", "UPDATE", "UPPER", "USAGE", "USER", "USING", "VALUE", "VALUES", "VARCHAR", "VARYING", "VIEW", "WHEN", "WHENEVER", "WHERE", "WHILE", "WINDOW", "WITH", "WITHIN", "WITHOUT", "WORK", "WRITE", "YEAR", "ZONE"); foreach($keywords as $keyword) foreach($arr as $item) if ($item == $keyword) return true; return false; } </code></pre> <p>I also thinking in saving all the queries that where entered by users and that matched any keyword to pinpoint some edge cases.</p> </div>

SQLSTATE [42S22]:未找到列:1054未知列一对多(反)关系laravel

<div class="post-text" itemprop="text"> <p>I have two models <code>Tour.php</code> and <code>TourCategory.php</code>:</p> <p><code>Tour.php</code></p> <pre><code>protected $table = `tours`; public function category() { return $this-&gt;belongsTo('App\TourCategory'); } </code></pre> <p><code>TourCategory.php</code></p> <pre><code>protected $table = 'tcategories'; public function tours() { return $this-&gt;hasMany('App\Tour'); } </code></pre> <p>My db tables are as follows:</p> <p><code>tours</code> table</p> <p><code>id|title|category_id|content|</code></p> <p><code>tcatgegories</code> table</p> <p><code>id|name</code></p> <p>And I have a view to show the all tours belonging to a category with the following code:</p> <pre><code> @foreach ($category-&gt;tours as $tour) &lt;tr&gt; &lt;th&gt;{{ $tour-&gt;id}}&lt;/th&gt; &lt;td&gt;{{ $tour-&gt;title}}&lt;/td&gt; &lt;td&gt; &lt;span class="label label-default"&gt;{{$category-&gt;name}}&lt;/span&gt; &lt;/td&gt; &lt;/tr&gt; @endforeach </code></pre> <p>With this above code I'm getting error of:</p> <pre><code>SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tours.tour_category_id' in 'where clause' (SQL: select * from `tours` where `tours`.`tour_category_id` = 1 and `tours`.`tour_category_id` is not null) (View: F:\multiauth_tutorial-master esources\ views\admin\categories\show.blade.php </code></pre> <p>I have used same code for my previous projects also but didn't had any errors. Or am I missing something ?</p> </div>

错误:字段列表中的未知列

<div class="post-text" itemprop="text"> <p>While running the below script it shows the errorError: Unknown column 'email' in 'field list'.</p> <pre><code> &lt;?php include("connect.php"); if($loggedin == '1') die("You can't register another account while you're logged in."); if(isset($_POST['submit'])) { $uname = trim($_POST['username']); if($_POST["regkey"]!="171717") die("Invalid Registration Key. &lt;br&gt; &lt;a href= register.php&gt;Back&lt;/a&gt;"); if($_POST["pass"]!=$_POST["pass2"]) die("Passwords do not match. &lt;br&gt; &lt;a href= register.php&gt;Back&lt;/a&gt;"); // Make sure all forms were filled out. if((!isset($_POST['username'])) || (!isset($_POST['pass'])) || ($uname == '') || ($_POST['pass'] == '')) die("Please fill out the form completely. &lt;br&gt;&lt;br&gt; &lt;a href=register.php&gt;Continue&lt;/a&gt;"); $check = @mysql_query("SELECT id FROM players WHERE username = '$uname'"); $check = @mysql_num_rows($check); if($check &gt; 0) die("Sorry, that username has already been taken. Please try again. &lt;br&gt;&lt;br&gt; &lt;a href=register.php&gt;Continue&lt;/a&gt;"); $pass = md5($_POST['pass']); $date = date("m/d/y"); $newPlayer = @mysql_query("INSERT INTO players (username, password, registered,callname,email) VALUES ('$uname','$pass','$date','$_POST [callname]','$_POST[email]')") or die("Error: ".mysql_error()); echo 'You have been registered! You may now &lt;a href=index.php&gt;Log in&lt;/a&gt;.'; } else { // A simple example of a form. echo ' &lt;center&gt; &lt;form action=register.php method=post&gt; &lt;p&gt;Registration is currently&lt;b&gt; NOT OPEN.&lt;/b&gt;&lt;br&gt; You must have a valid Registration key to register.&lt;/p&gt; &lt;table border="2"&gt; &lt;tr&gt; &lt;td&gt;Username:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="username" size="20px"&lt;/input&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Callname:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="callname" size="20px"&lt;/input&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Password:&lt;/td&gt;&lt;td&gt;&lt;input type="password" name="pass" size="20px"&lt;/input&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Re-type Password:&lt;/td&gt;&lt;td&gt;&lt;input type="password" name="pass2" size="20px"&lt;/input&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Email:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="email" size="20px"&lt;/input&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Registration Key:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="regkey" size="20px"&gt;&lt;/input&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type="submit" name="submit" value="Submit"&gt;&lt;/input&gt; &lt;/form&gt;'; } ?&gt; </code></pre> <p>I'm very new to PHP and can't figure out why I'm getting this Error. Shouldn't the $_POST get that value from the form? Thanks for reading.</p> </div>

'where子句'中的未知列

<div class="post-text" itemprop="text"> <p>So I am trying to add a drop down list which will call the data of a particular field of table in db, and show it, then when I click on the list, some data will be shown accordingly. </p> <p>Now the problem is, I did good in first two lists, then when I testing my third list, it will show "Unknown column 'alumn.work.field' in 'where clause'".</p> <p>Below is my code to call the variable from my table in database:</p> <pre><code>// Start : Job list mysql_select_db($database_cnJw, $cnJw); $query_rs_job = "SELECT field FROM alumn_work"; $rs_job = mysql_query($query_rs_job, $cnJw) or die(mysql_error()); $row_rs_job = mysql_fetch_assoc($rs_job); $totalRows_rs_job = mysql_num_rows($rs_job); // End : Job list </code></pre> <p>and here is the code to add the drop down list:</p> <pre><code>&lt;select name="alumn_work_field"&gt; &lt;option value="" selected="selected"&gt;&lt;/option&gt; &lt;?php do { ?&gt; &lt;option value="&lt;?php echo $row_rs_job['field']?&gt;"&gt;; &lt;?php echo $row_rs_job['field']?&gt;&lt;/option&gt; &lt;?php } while ($row_rs_job = mysql_fetch_assoc($rs_job)); $rows = mysql_num_rows($rs_job); if($rows &amp;gt; 0) { mysql_data_seek($rs_job, 0); $row_rs_job = mysql_fetch_assoc($rs_job); } ?&gt;; &lt;/select&gt; </code></pre> <p>I myself think the problem will be occur here:</p> <pre><code> &lt;select name="alumn_work_field"&gt;; </code></pre> <p>but I not sure what is the problem. Can anyone tel me what is the problem?</p> </div>

Laravel试图播种未被要求的专栏

<div class="post-text" itemprop="text"> <p>I have a strange problem and an hour of googling and searching through stackoverflow didn't get me any closer to a solution. What happens is that when I trye to seed a table (let's call it <code>my_table</code> for security purposes) the seeder seems to try to populate columns that I never asked to be seeded.</p> <p>So, first I run <code>php artisan migrate</code> to create my table using the following migration:</p> <pre><code>&lt;?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class CreateMyTableTable extends Migration { /** * Run the migrations. */ public function up(): void { Schema::create('my_table', function (Blueprint $table) { $table-&gt;increments('id'); $table-&gt;integer('user_id')-&gt;unsigned(); $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('user'); $table-&gt;tinyInteger('from_default')-&gt;nullable(false)-&gt;default(7); $table-&gt;tinyInteger('to_default')-&gt;nullable(false)-&gt;default(20); $table-&gt;timestamps(); $table-&gt;unique('user_id'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('my_table', function (Blueprint $table) { $table-&gt;dropUnique(['user_id']); $table-&gt;dropForeign(['user_id']); }); } } </code></pre> <p>This works well, and when I do <code>DESCRIBE my_table</code> I get the following:</p> <pre><code>Field Type Null Key Default Extra ------------------------------------------------------------------------------- id int(10) unsigned NO PRI auto_increment user_id int(10) unsigned NO UNI from_default tinyint(4) NO 7 to_default tinyint(4) NO 20 created_at timestamp YES updated_at timestamp YES </code></pre> <p>So you can see that the table is created with the exact fields that I want in my migration file. So, now I want to seed this table using the following seed:</p> <pre><code>&lt;?php use App\DomainLogic\Models\MyTable; use App\DomainLogic\Models\User; use Faker\Factory as FakerFactory; use Illuminate\Database\Seeder; class MyTableTableSeeder extends Seeder { /** * @var array list of MyTable Users */ private $myTableUsers = []; /** * Run the database seeds. */ public function run() { $this-&gt;createMyTableUsers(); $myTableUsers = $this-&gt;getMyTableUsers(); foreach ($myTableUsers as $myTableUser) { factory(MyTable::class)-&gt;create([ 'user_id' =&gt; $myTableUser-&gt;getKey(), 'from_default' =&gt; 7, 'to_default' =&gt; 20, ]); } } private function getMyTableUsers(): array { return $this-&gt;myTableUsers; } private function createMyTableUsers() { $faker = FakerFactory::create(); // My table $this-&gt;myTableUsers[] = factory(User::class)-&gt;create([ 'id' =&gt; 2, 'first_name' =&gt; 'Kalle', 'last_name' =&gt; 'Andersson', 'email' =&gt; 'kalle.andersson@email.com', 'password' =&gt; bcrypt('password', ['rounds' =&gt; 4]), 'mobile_number' =&gt; $faker-&gt;e164PhoneNumber, ]); $this-&gt;myTableUsers[] = factory(User::class)-&gt;create([ 'id' =&gt; 3, 'first_name' =&gt; 'Johan', 'last_name' =&gt; 'Petterson', 'email' =&gt; 'johan.petterson@email.com', 'password' =&gt; bcrypt('password', ['rounds' =&gt; 4]), 'mobile_number' =&gt; $faker-&gt;e164PhoneNumber, ]); $this-&gt;myTableUsers[] = factory(User::class)-&gt;create([ 'id' =&gt; 4, 'first_name' =&gt; 'Krister', 'last_name' =&gt; 'Johansson', 'email' =&gt; 'krister.johansson@email.com', 'password' =&gt; bcrypt('password', ['rounds' =&gt; 4]), 'mobile_number' =&gt; $faker-&gt;e164PhoneNumber, ]); $this-&gt;myTableUsers[] = factory(User::class)-&gt;create([ 'id' =&gt; 5, 'first_name' =&gt; 'Daniel', 'last_name' =&gt; 'Eriksson', 'email' =&gt; 'daniel.eriksson@email.com', 'password' =&gt; bcrypt('password', ['rounds' =&gt; 4]), 'mobile_number' =&gt; $faker-&gt;e164PhoneNumber, ]); } } </code></pre> <p>When running <code>php artisan db:seed</code> I get this error:</p> <pre><code>In Connection.php line 664: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'starts_day_default' in 'field list' (SQL: insert into `my_table` (`user_id`, `starts_day_default`, `ends_day_default`, `from_default`, `to_default`) values (2, 07, 20, 7, 20)) In PDOConnection.php line 82: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'starts_day_default' in 'field list' In PDOConnection.php line 80: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'starts_day_default' in 'field list' </code></pre> <p>So the strange thing is that as far as I see, I never try to populate a column called <code>starts_day_default</code> or <code>ends_day_default</code>. Because those columns don't exist and should not exist. The actual thing is that the columns were renamed <code>starts_day_default -&gt; from_default</code> and <code>ends _day_default -&gt; to_default</code>. The users are created correctly, I can see them in the users table, so that is not the problem. Here is also my model for MyTable:</p> <pre><code>&lt;?php namespace App\DomainLogic\Models; use DateTimeImmutable; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; class MyTable extends Model { /** * Indicates if the model should be timestamped. * * @var bool */ public $timestamps = false; /** * The table associated with the model. * * @var string */ protected $table = 'my_table'; /** * Creates personal trainer, if personal trainer with id exists. * * @param int $myTableId * * @return null|self */ public static function createFromId(int $myTableId): ?self { $myTable = self::select('my_table.*') -&gt;join('user', 'user.id', '=', 'my_table.user_id') -&gt;where('my_table.id', '=', $myTableId) -&gt;whereNull('user.anonymized_at') -&gt;get() -&gt;first(); return $myTable; } /** * Create personal trainer, if user_id exists. * * @param int $userId * * @return null|MyTable */ public static function createFromUserId(int $userId): ?self { return self::where('user_id', $userId)-&gt;get()-&gt;first(); } /** * Gets all personal trainers. * * @param bool $active * * @return Collection */ public static function getMyTables(bool $active = null): Collection { $query = self::select('my_table.*') -&gt;join('user', 'user.id', '=', 'my_table.user_id') -&gt;whereNull('user.anonymized_at'); if (isset($active)) { $query-&gt;where('user.active', '=', $active); } $myTables = $query-&gt;get(); return $myTables; } /** * Gets user. */ public function getUser(): User { $user = $this-&gt;belongsTo(User::class, 'user_id', 'id')-&gt;getResults(); return $user; } /** * Check if personal trainers ids are valid. * * @param array $myTableIds * * @return bool */ public static function areMyTableIdsValid(array $myTableIds): bool { $dbMyTableIds = self::select('my_table.id') -&gt;join('user', 'user.id', '=', 'my_table.user_id') -&gt;whereIn('my_table.id', $myTableIds) -&gt;whereNull('user.anonymized_at') -&gt;get() -&gt;pluck('id') -&gt;toArray(); $dbMyTableIds = array_map('intval', $dbMyTableIds); sort($myTableIds); sort($dbMyTableIds); $result = false; if ($myTableIds === $dbMyTableIds) { $result = true; } return $result; } } </code></pre> <p>I have tried</p> <pre><code>php artisan view:clear php artisan cache:clear php artisan debugbar:clear composer dump-autoload </code></pre> <p>suggested in <a href="https://stackoverflow.com/questions/48847321/unknown-column-username-in-laravel">Unknown column 'username' in Laravel</a> but that did not help. I have dropped all tables and rerun <code>php artisan migrate</code> but that did not help either.</p> <p>I have never seen this before, so my question is, can anyone see what my problem is?</p> </div>

zf2 doctrine2如何在实体列中使用tinyint数据类型

<div class="post-text" itemprop="text"> <p>I am using Doctrine 2 ORM with ZF2. </p> <pre><code>/** * * @ORM\Column(type="tinyint", options={"default" = 1}) */ protected $isActive; </code></pre> <p>How can I create tinyint type of column, as I can see in <a href="http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html">support data type of doctrine</a>, it does not exist. </p> <pre><code>Commandline&gt;# ./vendor/bin/doctrine-module orm:validate-schema [Mapping] FAIL - The entity-class 'Application\Entity\User' mapping is invalid: * The field 'Application\Entity\User#isActive' uses a non-existant type 'tinyint'. [Doctrine\DBAL\DBALException] Unknown column type "tinyint" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypeMap(). If this error occurs during database introspection then you might have forgot to register all database types for a Doctrine Type. Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseT ypes(). If the type name is empty you might have a problem with the cache or forgot some mapping information. orm:validate-schema </code></pre> </div>

MySQL添加用户时报错,没有password字段

今天在菜鸟教程学mysql时,想往mysql 数据库中的 user 表添加新用户: 报错提示: > MySQL添加用户时报错 'ERROR 1054 (42S22): Unknown column 'password' in 'field list'' ``` INSERT INTO user ( host, user, password, select_priv, insert_priv, update_priv) VALUES ('localhost', 'guest', PASSWORD('123456'), 'Y', 'Y', 'Y'); ``` 而我 DESCRIBE user; 后发现确实没有password这个字段 请问该如何解决?

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

springboot+jwt实现token登陆权限认证

一 前言 此篇文章的内容也是学习不久,终于到周末有时间码一篇文章分享知识追寻者的粉丝们,学完本篇文章,读者将对token类的登陆认证流程有个全面的了解,可以动态搭建自己的登陆认证过程;对小项目而已是个轻量级的认证机制,符合开发需求;更多精彩原创内容关注公主号知识追寻者,读者的肯定,就是对作者的创作的最大支持; 二 jwt实现登陆认证流程 用户使用账号和面发出post请求 服务器接受到请求后使用私...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

总结了 150 余个神奇网站,你不来瞅瞅吗?

原博客再更新,可能就没了,之后将持续更新本篇博客。

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

程序员写出这样的代码,能不挨骂吗?

当你换槽填坑时,面对一个新的环境。能够快速熟练,上手实现业务需求是关键。但是,哪些因素会影响你快速上手呢?是原有代码写的不够好?还是注释写的不够好?昨夜...

外包程序员的幸福生活

今天给你们讲述一个外包程序员的幸福生活。男主是Z哥,不是在外包公司上班的那种,是一名自由职业者,接外包项目自己干。接下来讲的都是真人真事。 先给大家介绍一下男主,Z哥,老程序员,是我十多年前的老同事,技术大牛,当过CTO,也创过业。因为我俩都爱好喝酒、踢球,再加上住的距离不算远,所以一直也断断续续的联系着,我对Z哥的状况也有大概了解。 Z哥几年前创业失败,后来他开始干起了外包,利用自己的技术能...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

2020阿里全球数学大赛:3万名高手、4道题、2天2夜未交卷

阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

早上躺尸,晚上干活:硅谷科技公司这么流行迟到?

硅谷科技公司上班时间OPEN早已不是什么新鲜事,早九晚五是常态,但有很多企业由于不打卡,员工们10点、11点才“姗姗来迟”的情况也屡见不鲜。 这种灵活的考勤制度为人羡慕,甚至近年来,国内某些互联网企业也纷纷效仿。不过,硅谷普遍弹性的上班制度是怎么由来的呢?这种“流行性迟到”真的有那么轻松、悠哉吗? 《动态规划专题班》 课程试听内容: 动态规划的解题要领 动态规划三大类 求最值/计数/可行性 常...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

终于懂了TCP和UDP协议区别

终于懂了TCP和UDP协议区别

Python爬虫,高清美图我全都要(彼岸桌面壁纸)

爬取彼岸桌面网站较为简单,用到了requests、lxml、Beautiful Soup4

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

Java岗开发3年,公司临时抽查算法,离职后这几题我记一辈子

前几天我们公司做了一件蠢事,非常非常愚蠢的事情。我原以为从学校出来之后,除了找工作有测试外,不会有任何与考试有关的事儿。 但是,天有不测风云,公司技术总监、人事总监两位大佬突然降临到我们事业线,叫上我老大,给我们组织了一场别开生面的“考试”。 那是一个风和日丽的下午,我翘着二郎腿,左手端着一杯卡布奇诺,右手抓着我的罗技鼠标,滚动着轮轴,穿梭在头条热点之间。 “淡黄的长裙~蓬松的头发...

大胆预测下未来5年的Web开发

在2019年的ReactiveConf 上,《Elm in Action》的作者Richard Feldman对未来5年Web开发的发展做了预测,很有意思,分享给大家。如果你有机会从头...

立即提问
相关内容推荐