Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Notifications
Mark all as read
Q&A

Categories aren't seeded Question

+1
−0

I followed the instructions here, but even after running rails db:seed, there aren't any categories.

Console:

[email protected]:~/qpixel$ rails db:create
Running via Spring preloader in process 11391
Created database 'qpixel_dev'
Created database 'qpixel_test'
[email protected]:~/qpixel$ rails db:schema:load
[email protected]:~/qpixel$ rails r db/scripts/create_tags_path_view.rb
Running via Spring preloader in process 11401
[email protected]:~/qpixel$ rails db:migrate
Running via Spring preloader in process 11406
[email protected]:~/qpixel$ rails c
Running via Spring preloader in process 11412
Loading development environment (Rails 7.0.4)
irb(main):001:0> Community.create(name: 'Dev Community', host: 'localhost:3000')
  TRANSACTION (0.6ms)  BEGIN
  Community Exists? (0.9ms)  SELECT 1 AS one FROM `communities` WHERE `communities`.`host` = 'localhost:3000' LIMIT 1
  Community Create (0.5ms)  INSERT INTO `communities` (`name`, `host`, `created_at`, `updated_at`, `is_fake`, `hidden`) VALUES ('Dev Community', 'localhost:3000', '2022-09-19 00:34:06', '2022-09-19 00:34:06', FALSE, FALSE)
  TRANSACTION (16.7ms)  COMMIT
=>
#<Community:0x0000564c6852e710
 id: 1,
 name: "Dev Community",
 host: "localhost:3000",
 created_at: Mon, 19 Sep 2022 00:34:06.000000000 UTC +00:00,
 updated_at: Mon, 19 Sep 2022 00:34:06.000000000 UTC +00:00,
 is_fake: false,
 hidden: false>
irb(main):002:0> Rails.cache.clear
=> nil
[email protected]:~/qpixel$ rails db:seed
Running via Spring preloader in process 11439
PostType: Created 5, skipped 0
CloseReason: Created 5, skipped 0
License: Created 5, skipped 0
TagSet: Created 3, skipped 0
PostHistoryType: Created 12, skipped 0
Ability: Created 7, skipped 0
Category: Created 0, skipped 2
PostFlagType: Created 4, skipped 0
Post: Created 15, skipped 5
ReactionType: Created 3, skipped 0
SiteSetting: Created 67, skipped 0
User: Created 1, skipped 0
WarningTemplate: Created 3, skipped 0

http://localhost:3000/categories:

Image alt text

Checking via console:

[email protected]:~/qpixel$ rails c
Running via Spring preloader in process 11500
Loading development environment (Rails 7.0.4)
irb(main):001:0> Category.all.to_a
  Category Load (0.6ms)  SELECT `categories`.* FROM `categories` WHERE `categories`.`community_id` IS NULL
=> []

Clearly, the categories haven't been seeded. What did I do wrong, and how do I fix this?

Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

2 answers

+1
−0

I do not really know why rails db:schema:load stopped giving output, but it still does create all the tables as intended. The seeding of categories did indeed break due to rails being more strict on required elements for its relations. I have addressed this issue in https://github.com/codidact/qpixel/pull/897 .

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+0
−0

I checked out dc354484de405b4f7fd5fb4315e7408b85a5b2e3 (Aug. 15), where the specified Ruby version was 2.7.6, and the specified Rails version was ~> 5.2 (on my device, it realized as 5.2.6).

Running this version of QPixel gave me the following upon setting up:

[email protected]:~/qpixel$ rails db:schema:load
-- create_table("abilities", {:options=>"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", :force=>:cascade})
   -> 0.1009s
-- create_table("ability_queues", {:options=>"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", :force=>:cascade})
   -> 0.0866s
-- create_table("active_storage_attachments", {:options=>"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci", :force=>:cascade})
   -> 0.0997s
[...]

As you can see, it actually gave output. Secondly, upon running seeds, it actually seeded the categories (created 2, skipped 0, as I remember).

I believe that this means that Rails or Ruby made a breaking change somewhere between Rails 5 and Rails 7, which prevents seeding from working properly.

After successfully setting up the instance with that earlier commit, I then checked out a more recent commit and successfully migrated the database.

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »

This community is part of the Codidact network. We have other communities too — take a look!

You can also join us in chat!

Want to advertise this community? Use our templates!

Like what we're doing? Support us! Donate