• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 2.0 Creating a thread post via code?

Siropu

Well-known member
#1
I'm trying to create a thread post using a code and I get this error:
SQL:
MySQL query error [1364]: Field 'position' doesn't have a default value in src/XF/Db/AbstractStatement.php at line 183
I use this code:
PHP:
$post = $this->em()->create('XF:Post');
$post->thread_id = $id;
$post->user_id = $userId;
$post->username = $username;
$post->message = $message;
$post->save();
Is there a better way?