我正在尝试编写laravel数据库迁移,但是我收到有关外键的以下错误:
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'category_id' doesn't exist in table (SQL: alter table `subcategories` add constraint subcategories_category_id_foreign foreign key (`category_id`) references `categories` (`id`))
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'category_id' doesn't exist in table
Run Code Online (Sandbox Code Playgroud)
在categories与subcategories表确实会创建,但外键不.这是我的迁移:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCategoryTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('categories', function ($table) {
$table->increments('id')->unsigned();
$table->string('name')->unique();
}); …Run Code Online (Sandbox Code Playgroud) 我在我的节点中收到以下错误,无法弄清楚原因:
TypeError: Bad arguments
at Object.fs.readFileSync (fs.js:277:11)
at getSeries (/Users/user/tv/final.js:57:16)
at /Users/user/tv/final.js:89:4
at /Users/user/tv/node_modules/async/lib/async.js:610:21
at /Users/user/tv/node_modules/async/lib/async.js:249:17
at iterate (/Users/user/tv/node_modules/async/lib/async.js:149:13)
at /Users/user/tv/node_modules/async/lib/async.js:160:25
at /Users/user/tv/node_modules/async/lib/async.js:251:21
at /Users/user/tv/node_modules/async/lib/async.js:615:34
at /Users/user/tv/final.js:86:4
Run Code Online (Sandbox Code Playgroud)
我很确定它与我使用的异步npm软件包无关,因为我在开始使用之前遇到了同样的错误.
这是代码:
function getSeries() {
JSON.parse(fs.readFileSync('updates.json', function(err,data) {
if (err) {
console.error(err);
}
else {
var json = data;
}
}));
Run Code Online (Sandbox Code Playgroud) 我对 Spring (REST) 有点陌生,我正在构建一个简单的 REST web 服务。我使用 aRestController来映射 HTTP 请求。我使用这个简单的方法来接受一个 POST 请求:
@RequestMapping(value = "/grade/create", method = RequestMethod.POST)
public ResponseEntity<Grade> createGrade(@RequestBody Grade grade)
{
dao.createGrade(grade);
return new ResponseEntity<Grade>(grade, HttpStatus.OK);
}
Run Code Online (Sandbox Code Playgroud)
dao在这种情况下是一个带有@Repository注释的类。一个请求应该是这样的:
{
"gradeType": "REGULAR",
"grade": "10",
"passed": 1,
"userId": 1,
"exam_id": 1,
"user_id": 3
}
Run Code Online (Sandbox Code Playgroud)
问题是,它Grade有 2 个外键,用于用户和考试。我希望能够只传递外部实体的 ID,让 Hibernate 处理其余的事情。但是,目前我得到这个作为回应:
{
"timestamp": 1484758525821,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.dao.InvalidDataAccessResourceUsageException",
"message": "could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: …Run Code Online (Sandbox Code Playgroud) 我正在为JSON API编写SDK,但遇到了一个看似奇怪的问题。该API在POST数据验证方面非常严格,并且在更新资源(例如)时不允许出现某些参数id。因此,我添加@Expose(serialize = false)了资源类的ID字段。但是,它似乎仍对该字段进行序列化,导致请求被拒绝。资源类大致如下:
public class Organisation extends BaseObject
{
public static final Gson PRETTY_PRINT_JSON = new GsonBuilder()
.setPrettyPrinting()
.create();
@Expose(serialize = false)
@SerializedName("_id")
private String id;
@SerializedName("email")
private String email;
@SerializedName("name")
private String name;
@SerializedName("parent_id")
private String parentId;
public String toJson()
{
return PRETTY_PRINT_JSON.toJson(this);
}
}
Run Code Online (Sandbox Code Playgroud)
我的单元测试Organisation通过API 创建一个实例,将新创建的实例作为类参数保存到测试类中,并调用一个update方法,该方法将通过更新新资源来测试SDK的更新实现。这就是问题所在。即使toJson()在新方法上调用了该方法以将Organisation其序列化为JSON以进行更新请求,该_id字段仍然存在,从而导致API拒绝更新。测试代码如下。请注意代码中的注释。
@Test
public void testCreateUpdateAndDeleteOrganisation() throws RequestException
{
Organisation organisation = new Organisation();
organisation.setParentId(this.ORGANISATION_ID);
organisation.setName("Java Test Organisation");
Organisation newOrganisation = …Run Code Online (Sandbox Code Playgroud) 我正在 Laravel 5.5 中构建一个 GraphQL API,我收到一个错误消息User::create(),说我没有为“密码”列提供值,即使我确实提供了。这是来自User::create():的完整消息:
SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column \"password\" violates not-null constraint
DETAIL: Failing row contains (507, null, null, 2017-09-23 14:12:11, 2017-09-23 14:12:11, 658495, 56854685, Joe, Appleseed, royal, 1970-01-01, +31684736248, null, Poplar St, 14a, 1012AB, London, null, joe.appleseed@overwatch.com, joe.appleseed@mindef.nl, null). (SQL: insert into \"users\" (\"wid\", \"unumber\", \"first_name\", \"last_name\", \"civil_status\", \"birthdate\", \"phone_number\", \"street\", \"street_number\", \"postal_code\", \"city\", \"email_address_overwatch\", \"email_address_mindef\", \"updated_at\", \"created_at\") values (658495, 56854685, Joe, Appleseed, royal, 1970-01-01, +31684736248, Poplar …Run Code Online (Sandbox Code Playgroud)